gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Help needed on some angle maths...

#15750 - MumblyJoe - Thu Jan 29, 2004 2:36 am

Ok, I am working on a game that uses the lunar lander style controls for a ship, so say for example the left and right keys rotate the ship left or right and the up key fires a booster and makes the ship go faster in the direction it is facing, if there are no boosters then turning the ship doesnt change the direction or speed the ship is moving. I use a speedx and speedy variables (signed for up/down whatever) to say how the ship moves in the next frame.

My question is, if the booster is fired and I know what angle the ship is rotated to and facing, how do I calculate how much the x and y change? So if the ship is on say a 10 degree angle, mostly the speedx gains and the speedy changes less (naturally if the ship turns around to face to way it is coming from and fires the boosters it should decelerate, but thats a part of the math I would imagine anyway...).

Any ideas?
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#15751 - sajiimori - Thu Jan 29, 2004 2:55 am

http://forum.gbadev.org/viewtopic.php?t=1935

#15752 - animension - Thu Jan 29, 2004 3:43 am

The thread sajimori linked to will help establish how to move a sprite in a direction, but it won't tell you how to move it with acceleration / deceleration as a consideration.

This kind of mathematics is covered at length in many mechanical (classical) physics books, but this one in particular is focused on the kinds of physics games deal with most often: http://www.oreilly.com/catalog/physicsgame/index.html

If you are planning on doing any kind of trajectory math and you don't understand the fundamentals of the physics involved, I highly recommend this book.
_________________
"Beer is proof that God loves us and wants us to be happy."
-- Benjamin Franklin

#15754 - tepples - Thu Jan 29, 2004 4:54 am

here's how to make an Euler-integrated Asteroids style physics engine in floating point pseudocode. To convert to fixed-point, add a few divisions by a power of 2.
Code:
dx += cos_table[heading] * thrust;
dy += sin_table[heading] * thrust + gravity;
dx = dx * drag;
dy = dy * drag;
x += dx;
y += dy;

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#15758 - sajiimori - Thu Jan 29, 2004 9:04 am

I figured the rest was obvious after the initial bit of trig. ;-)

#15786 - MumblyJoe - Fri Jan 30, 2004 4:59 am

Thanks tepples, that algorithm works great with a few changes. I am still tweaking some things and values because it looks jerky, but besides that I am wrapped, I was racking my brain trying to figure it out.
_________________
www.hungrydeveloper.com
Version 2.0 now up - guaranteed at least 100% more pleasing!

#15809 - Miked0801 - Fri Jan 30, 2004 7:20 pm

Use Fixed Point math to eliminate the jerkiness as per his comments.