## Thrust Style calculations?

Scoops
Unregistered

Post: #1
I was thinking of putting together a game for this years competition and so thought about a 'Thrust' or 'Gravitar' style game. While thinking about the kind of calculations involved I couldn't help think that a nifty bit of maths would be in order. Seeing as I don't know any I am asking for any help on the matter. Inertia and gravity seem pretty straight forward but what about knowing which way you are pointing and therefore calculating the correct directions??

kainsin
Unregistered

Post: #2
I've never played those games so I'm not sure what they're like exactly. Assuming that they are 2D and consist of some sort of plane movement then I might suggest that you try using cylindrical coordinates to represent the plane's direction.

You specify cylindrical coordinates with a length ( r ) and an angle ( theta ). The angle represents the degrees above the x-axis. In this way and angle of 0-degrees = an angle of 360-degrees.

Now, the plane's position is at ( x, y ) = ( 0, 0 ) and if it is facing 45-degrees above the x-axis then it's direction vector is ( r, theta ) = ( 1, 45 ).

To convert from cylindrical to rectangular ( i.e. the x-y coordinate system ) then:

x = r * cos( theta )
y = r * sin( theta )

Now you can convert the directional vector to rectangular, add the components to the position, and know the location that the plane is facing.

There's a lot more math that might be helpful in this regard. I'd suggest looking into a Linear Algebra book for tips on matrix mathematics that can make some calculations pretty easy. Also, if you want to wander around with a coordinate grid of any sort, then a good geometry book will be handy too.
Member
Posts: 40
Joined: 2002.04
Post: #3
Assuming you want it to behave like Escape Velocity, I find that this works, but I haven't used it for a while so im a bit unsure:

xvelocity=xvelocity+2*SIN(Angle+pi)
yvelocity=yvelocity+2*COS(Angle+pi)

Im pretty sure the 2 is just a coefficient of thrust. And make sure angle is in radians.

Just add on xvelocity and yvelocity to your x and y coordinates of the ship and your done!

Just incase you didn't know:
To convert degrees to radians, simply multiply by pi/180. To convert radians to degrees, multiply by 180/pi.

(side note: I've never understood why SIN finds x in this case. I thought SIN was for y? If someone could explain this to me that would be helpful!)
kainsin
Unregistered

Post: #4
Sin should be for y and Cos should be for x. Of course that is assuming that you want the angle to start along the positive x-axis and increase towards the positive y-axis. Since it's just math you can easily assume that the angle starts along a different axis and adjust your calculations as such, but I think that this is the easiest way to visualize it.
Founder
Posts: 1,141
Joined: 2002.04
Post: #5
Is the game 2d or 3d? Just wondering.

Carlos A. Camacho,
Founder
iDevGames
Member
Posts: 304
Joined: 2002.04
Post: #6
You could check out the asteroid.c source example which is in Developer/Examples/GLUTExamples/gameglut/

cheers,
Codemattic
Member
Posts: 196
Joined: 2002.04
Post: #7
Check out the source code for Quartzeroids (it's on download.com and versiontracker.com). I'm using it for an Asteroids type game and it's proved very helpful.

Iceman
Scoops
Unregistered

Post: #8
Thanks, I will try and check out the source for those programs. In response to your question this would be a 2D game for a couple of reasons. One is that given the game will be written in Basic (not counting RB), it's strength is it's 2D graphics performance. Also, I don't know if you could successfully integrate 3D into this style of game???