Hi, I''m developing a racing game, and have run into a bit of a problem, at the moment I store the speed and the direction the vehicle is facing, and then work out movement with these values, but now I can''t figure out how to make the vehicle slide or bounce off of walls or anything because I don''t want to change the way its facing, just the way its moving. So should I be representing the speed with an X,Y and Z componants individually, or should I add another angle which holds the way its actually moving, and if I do add another angle then how do I work out which direction it should be moving?
Any help appreciated, but please don''t point me to the PHOR document, I''ve read it, and although its very detailed it doesn''t really help with programming.
----------------
Freeride Designs
----------------
Racing game trouble
The way i would do it is to represent your direction of travel with a velocity vector (the speed in a particular direction).
Each frame you would add this vector to your current position.
The speed of travel is the magnitude of this vector.
To increase the speed by X% is (magnitude of vector x (X/100)) x normalised vector. ie to increase speed by a tenth, X = 110 to reduce speed by a tenth X = 90
Then you need a heading vector (the direction your car is facing) usually normalised.
You would then resolve these two vectors ( sutract them for a gradual slow down) each frame. Usually they will be facing in the same direction (for traveling forwards).
To handle skids and spins, alter this heading vector (and possibly its magntitude dependant on friction, downforce from aerodynamics at speed etc).
Crashes would be handled the same way. determine a new heading vector from the collision.
This is off the top of my head, so maybe it needs a few other factors including, but its a good start.
Each frame you would add this vector to your current position.
The speed of travel is the magnitude of this vector.
To increase the speed by X% is (magnitude of vector x (X/100)) x normalised vector. ie to increase speed by a tenth, X = 110 to reduce speed by a tenth X = 90
Then you need a heading vector (the direction your car is facing) usually normalised.
You would then resolve these two vectors ( sutract them for a gradual slow down) each frame. Usually they will be facing in the same direction (for traveling forwards).
To handle skids and spins, alter this heading vector (and possibly its magntitude dependant on friction, downforce from aerodynamics at speed etc).
Crashes would be handled the same way. determine a new heading vector from the collision.
This is off the top of my head, so maybe it needs a few other factors including, but its a good start.
you know, i was thinking of doing the same thing, add two different vectors for linear velocity and orientation, but i ended up coding an entire physics engine based on Chris Hecker''s articles, and other sources, instead. with the articles, i was able to code an engine that allows skidding, and other things, but for the most part, yeah, you''d have to learn all the physics if you want anything decent-looking. but props to you if you can get it looking good without a full-blown physics engine.
a2k
a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement