#122580 - Rajveer - Tue Mar 20, 2007 2:09 pm
Hi guys. I have a racing "ship" which has a few forces acting on it,a nd I want to know if my logic in calculating the final direction/speed of the ship is correct:
Forces:
Ship's thrust vector: We'll call this the thrust vector, or thrust velocity when not normalised. Direction is the same as the ship's z-axis.
Ship's speed: Speed at a given time, which I'll increase by a constant acceleration or decrease when no thrust, in the direction of the thrust vector.
Gravity vector: Simply (0, -1, 0) as it always acts downwards on a large scale.
Gravity speed: The speed at a given time of the ship in the -ve y-axis caused by the acceleration of gravity (only when no collision with the ground in my case).
Final vector: Final direction for the ship to move.
Final speed: Magnitude of the final vector before normalisation.
I'm thinking of breaking down the calculations as such:
Forces:
Ship's thrust vector: We'll call this the thrust vector, or thrust velocity when not normalised. Direction is the same as the ship's z-axis.
Ship's speed: Speed at a given time, which I'll increase by a constant acceleration or decrease when no thrust, in the direction of the thrust vector.
Gravity vector: Simply (0, -1, 0) as it always acts downwards on a large scale.
Gravity speed: The speed at a given time of the ship in the -ve y-axis caused by the acceleration of gravity (only when no collision with the ground in my case).
Final vector: Final direction for the ship to move.
Final speed: Magnitude of the final vector before normalisation.
I'm thinking of breaking down the calculations as such:
Code: |
---------------------------- -Left/Right held: *Rotate ship left/right -A held: *Increase ship thrust speed i.e. ship accelerates along ship's z-axis -A NOT held: *Decrease ship thrust speed -Limit ship speed: *Cannot exceed maximum speed, cannot go below 0 -Combine Ship's thrust vector and speed with finalvector and final speed (from previous frame): *Q: Would I combine the ship's non-normalised thrust vector (so magnitude = thrust speed) with the ship's non-normalised final vector (from the previous frame)?? If I do, every frame I'll be accelerating the ship with a constant force as I'll keep increasing the final vector's magnitude, so instead do I combine the ship's non-normalised thrust vector with the ship's NORMALISED final vector??? And then calculate the final speed from this?? (I.e. magnitude of the final vector) -Check Collision: *Check collision between polygons and line from ship's current position and future position *If intersection, move ship just infront of polygon so it doesn't pass through it IF Check Collision is false, move ship all the way from current position to future position -Check Ground Collision: *Fire ray from bottom of ship to polygons, check if intersects *If it does intersect and is within certain distance, rotate ship to matrix alignment of the ground (then next frame, the final vector will tend toward this rotation), apply friction i.e. final speed * 0.9f? *If not, apply gravity: increase "gravity speed" by gravitational acceleration, add to move vector. Again same question: would I add the non-normalised gravity vector to the non-normalised final vector?? ---------------------------- |