- Home /
(C#) How would I go about making physics like F-Zero GX's?
I'm in the process of creating a 3D futuristic racing game similar to F-Zero GX. I have tracks that are full of twists, turns, loops, slopes, and other things that require the car's gravity to follow the track, but I can't seem to figure out how to accomplish this. I've been searching for an answer all day to how I could accomplish this, but all solutions I have attempted have not worked. Any help would be appreciated, and just tell me if I need to provide more information.
Answer by Matt1000 · Nov 18, 2018 at 04:16 AM
I actually already did a mechanism like this one. Pretty much how Mario galaxy works. I'll break it down for you.
Basically, your objects gravity should be the terrain's normal. A plane's normal is a perpendicular vector to that plane. In other words is an "up" line from any surface. To calculate it you need to calculate the cross product of two vectors that are from the plane. The cross product is not a problem since you can simply do Vector2.Cross() and that it. You'll need two vectors parallel to the surface NOT parallel between them though.
It's really not that hard once you wrap your head around it.
To calculate a vector parallel to a surface you can simply use two points from that surface. You just do P2 - P1. and you'll get a vector from P1 towards P2. If you have another point you can do P3 - P1 and you'll have your two vectors. It's very important not to use three points in a row otherwise both vectors will be the same... Generally, P1 can be the point the player/object is on and if P2 is in front then P3 would be to the side (in front and the back won't work.)
IMPORTANT: If you are over curve objects you CANNOT use the point below you, since it will lead to the normal being a little off. If that's the case One vector needs to be P1 - P2 (P1 being in front of you and P2 to your back) and the other P3 - P4 (P3 to your right and P4 to your left). That will be enough to even the surface.
Once you have normal you just need to do a little trick. This normal can actually be 2 different vectors, might be the vector you need or the opposite one, in which case your object will start floating away. Just do a check from your object towards the vector that you got and if you hit something, then it's the right one. If you get the "up" vector, check if there is something. Since there won't be anything, use the other one.
NOTE: all these points need to be really near to you. Otherwise, it may not work very well. And many times this mechanism has problems with lowpoly objects.
After all that you can create extra things like stabilizers but that is the basis. Might seem hard but it a lot of simple things really.
Hope it helps ; )
I think I got the normal, now how would i set the gravity to it?