# Need equations to predict position/velocity when rotating+thrust

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I have a 2D networked space shooter that I am working on. On the server, for the purposes of client-synchronization, I have a function that updates the players coordinates as the server sees them. The server then periodically sends these coordinates to make sure that all clients are in sync and do not slowly drift out of sync, because the clients only send key presses to the server. It is also done this way to conserve bandwidth. The client, meanwhile, updates the logic state at a fixed rate (every 20 ms). The physics on the client end is very basic vector math, I don't even care about mass (so not using forces) or time (because it's updated at a constant rate). A ship in the game has 3 properties (parenthesis include values for an example ship I'm using): Acceleration - (0.1 in this case) Rotational velocity (omega) - (PI/60) Maximum speed - (7) It also has several other things that describe its relation to the game: Position, velocity, and orientation vectors. The orientation vector points from the center to the nose of the ship and is a unit vector, it is used to determine the acceleration vector (multiplied the scalar value of the acceleration of the ship, added to the velocity, checked for maximum speed, and then added to the position). Now for the actual problem: Using physics equations on the server to come up with the coordinates of the ship is easy for just rotation, or just thrusting. However, I have been unable to come up with equations that describe the ship's position and velocity when it is both thrusting and rotating. However, I have plotted the actual values produced by the client, and when the ship starts thrusting and rotating from a standstill position, the position graph seems to be that of a cycloid. So, is there any way to come up with such equations, that will take into consideration both the initial velocity of the ship and its orientation, and by plugging in t spit out its position (x and y) and velocity at that time? Thanks in advance! [Edited by - itistoday on August 20, 2005 6:50:01 PM]

##### Share on other sites
Additionally, for your convenience, here are two screenshots of two different position graphs (both starting from a standstill, but in one the ship is facing up, and in the other the ship was facing to the right). I have, through trial and error, adjusted the basic cycloid equation to match those of the graphs.

Starting by looking up
Starting by looking right

Edit: in those images, the 0.05236 value has absolutely no effect (it's PI/60), so you can just as easily remove it (substitute it with one).

[Edited by - itistoday on August 20, 2005 6:33:21 PM]

##### Share on other sites
Spaceship that rotates with constant angular velocity w=[number of revolutions per second]*2*pi and accelerates with constant linear acceleration a directed along ship's axis will be moving around circle, and center of this circle moves with constant velocity that depends to how spaceship starts it's motion.
In other words, if you stay in center of the circle and move with circle, spaceship's nose is always pointing to you, and thrust is equal to centrifugal force. From there everything could be easily derived.
Let's find properties of circle: radius of circle can be obtained from
a=w^2*r (acceleration is equal to angular velocity squared*radius) so r=a/(w^2)
and velocity of rotation around center is equal to
w*r=a/w
So: if the motion begins at point p with velocity v, pointing in direction d (d is unit-length vector), radius of circle is
r=a/(w^2)
center of circle is placed in p+d*r (infront of spaceshp) and are moving with velocity v+(a/w)*id where id is vector orthogonal to d.
From there you can figure it yourself.

Alternatively, it could be very nicely derived with complex numbers.
You have that dv(t)/dt=acceleration=d*a*ei*w*t (acceleration vector is rotating with angular velocity w , initial direction is d)
so integrating you get
v(t)=i*d*(a/w)*ei*w*t + const
and dp(t)/dt=v so integrating again
p(t)=-d*(a/w^2)*ei*w*t + const*t + const

So if we substitute proper constants, we get equation of motion
p(t) = p + (v+(a/w)*i*d)*t + (a/w^2)*d*(1-ei*w*t)
(Note that a/w^2 is radius) It's exactly same result, just derived other way.
Reading more about complex numbers and implementing motion into server is left as exercise for the reader ;)
BTW, better graph it, I might have some sign flipped somewhere.

Hope it helps.

BTW: you need to make client and server both use those equations. Typical way of doing thrust and rotation will give close but bit different results, because of imprecisions.
Also, i would suggest to do something else for cliend&server because with these equations you can't implement smoothly accelerating rotation.

edit: fixed typo (2 ---> 1)

[Edited by - Dmytry on August 23, 2005 4:51:13 AM]

##### Share on other sites
Thanks dmytry for that! However, most of that is way over my head. I'm not sure how to go about solving your first proposition, and I don't know calculus of complex numbers so I don't know where you got v(t)=i*d*(a/w)*ei*w*t + const.

I have asked around and found another solution that, no offense, I think is a bit easier:

Acceleration-x = A * cos(wt + initial-theta)
Acceleration-y = A * sin(wt + initial-theta)

Just integrate those for v(t) and p(t). :D

##### Share on other sites
--^ (that was me). Also, when integrating you have to watch out for the constants of course... And I meant to say I don't know where you got: dv(t)/dt=acceleration=d*a*ei*w*t
But I'm sure I'll find out when I get to calculus of complex numbers :-)

##### Share on other sites
well,
Acceleration_x = A * cos(wt + initial_theta)
Acceleration_y = A * sin(wt + initial_theta)
simply means "acceleration vector rotates with angular velocity w and initial position initial_theta" and nothing more. I.e. it is your original question. I have assumed thay you did wrote some working game code for client as you did said, and to write such code you shoulda knew it already isn't?

Anyway,
acceleration=a*d*ei*w*t
is precisely same thing as above. Just with complex numbers everything is shorter and more readable. [grin]

That's because complex exponent is defined as
ea+i*b=ea*(cos(b)+i*sin(b))
so for a=0 we get
ei*b=cos(b)+i*sin(b)
, in other words real part(you'd name it x) is equal to cosine and imaginary (you'd name it y) is equal to sine.
That is,
ei*b
gives you complex number pointing in direction with angle b . Just that. Complex numbers is very much like vectors*. Also, it's really lot shorter this way.

Then, just integrate the exponent and voila. (Actually, it's easier to remember how to integrate eb*i than to separately remember integrals of sin, cos, and exp)
[note: in my formula d is just direction of initial_theta; i.e. d=ei*initial_theta (so a*d*ei*w*t=a*ei*initial_theta*ei*w*t=ei*(w*t+initial_theta) ]

[*note: this post is written with assumption that you know idea of direction vector, based on "It also has several other things that describe its relation to the game: Position, velocity, and orientation vectors."]

[Edited by - Dmytry on August 23, 2005 7:36:41 AM]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633317
• Total Posts
3011336
• ### Who's Online (See full list)

There are no registered users currently online

×