Limit Rotation Blender Game Engine

Hey BlenderArtists,
I have a made a car, made out of 4 wheels attached to a body by rigid body constraints, and it works fine. The only problem is, if I go to fast and turn, or hit some kind of obstacle, it will turn/roll over and there is no way to get it back up and keep going. I know how to lock rotation, but I don’t want to do that because it doesn’t give me the right car effect I want. Does anyone know how to limit rotation, so an object won’t rotate all the way on a certain axis? Perhaps by code? I know there is a constraint that can do this but it doesn’t seem to work in BGE. Thank you!

~Olimation

keypress (flip)--------python

import bge
cont=bge.logic.getCurrentController()
own=cont.owner()
own.alignAxisToVect([0,0,1],2,.5))

this will flip you back over I think.

Attachments

flipDemo.blend (433 KB)

Thanks, but I really just don’t want the car to flip over at all. However this code does fix some other problems!

RotXYZ=own.worldOrientation.to_euler()
If RotXYZ.x > 90:
    Rot.XYZ.x=90
If RotXYZ.x <-90
    RotXYZ.x=-90

Attachments

NoFlip.blend (434 KB)

Thanks, but the wheels that are jointed to the body are having strange problems. Any fix for that, or maybe another solution?

yeah, apply torque instead of change rot,

this uses wrectified “TorqueTrackTo” and Force Move to,

but it needs updated, as I don’t know why I named anything the way I did

Torque = "“Force” to match a objects orientation

X1=Force to make a object move to another

Attachments

OldWrectifiedScriptModified.blend (438 KB)