If anyone could me, please!!
I want to know how to make a ship move in a specific direction, sort of like an astroids game. You point your ship in a direction in a specific direction and press accelerate and then it goes. In my book, Tricks of the windows game programming gurus, it talks about it but i don''t really get it. Help me please!!
"sorry 'bout the mess..." -Han Solo
um, i''d suggest reading harder.. and reading harder again, and again... and again??? if u need, this is the basic math: keep an angle A from 0 to 359 and the velocity of the ship. every cycle calc the direction vector using x = sin(A), y = cos(A). this gives u the unit vector (velocity of 1... whatever units u use). then multiply this vector by the velocity, so x = Velocity * cos(A).. etc. then just add the vector to ur current ship pos. obviously there must be a better way to do this.. but u get the idea.
then when you''re updating where your ship is every frame,
update() { x += vx; y += vy; // Might want to check if it goes off screen, etc. }
So basically, this code will give you a newtonian movement system, where you thrust once in a direction, and will continue to float in that direction until you apply a counterthrust.
All right i did that, but the ship only moves along the axes. I still don''t really get it. I am posting the code so that anyone can help me. go here ->
han-_-solo.tripod.com/help/aster.cpp
You need to include the Directx libraries.
P.S. to Andre LaMothe, yes this is coming almost directly from your book. hope this dosen''t count as copyright infringment
Probably the reason the ship is only moving on the axis is because you haven''t converted your angle from degrees to radians. sin and cos take radians.
Hi! I''m having some sort of the same problem, only that I''m doing it in 3D. How do you determine the direction for it to move in 3D? I''m keeping track of the roll, yaw and pitch angles for the object, but can''t figure out a proper equation that will make it move correctly. Any help?