I’m making a sonic game, and I want him to jump away from the surface he is standing on. The problem is I’m taking reference of The Sonic Physics Guide, from Sonic Retro, but this only applies to 2d games.
In 2d games, the formula to do it is something like this:
But in 3d… well I’m kinda stuck, I guess I could get the angle of the ground with hitNormal somehow, but have no idea on how the formula could be, because now i have two angles and three axis.
import bge
from mathutils import Vector
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
St = Vector ([0,0,-1])
Start = own.worldPosition+(own.worldOrientation * St)
St = Vector ([0,0,-2])
End= own.worldPosition+(own.worldOrientation * St)
hitObject, hitPoint, hitNormal = own.rayCast(End,Start, .0, "ground")
# check the orientation of the wall the player is hanging from and then use it for our own orientation
if hitNormal != None:
own.alignAxisToVect(hitNormal, 2, .8)
main()
It works, but it isn’t smooth, at least in the way i set it up. Is there a way not to use force, but instead set the linear Velocity along the vector for a split second, and then let the gravity do his job?
btw i’m using a motion actuator and artificial gravity.
But i don’t want to affect his rotation, otherwise if he jumped from a ceiling, he would draw an “U” in the air because while he was rotating back to the ground, the direction of the force was rotating as well. I mean, I just want to move sonic along the hitNormal by using world coordinates.