- Home /
Player model Rigidbody keeps falling upsidedown
Hi,
I've seen some questions like this on here but haven't been able to find an answer that works.
I have a "player character" (so far it's just a cube) that is a rigidbody and I do transform.Translate based on Input.GetAxis().
I have the rigidbody constrained to only move in the X and Y and have the rotation constrained to the Z axis, my problem is that my cube (more of a tall cuboid) can fall over when I move up and down the ramps and platforms I've made.
I've tried artificially constraining the player in the Z rotation such as:
Vector3 rot = transform.eulerAngles;
if(rot.z > 45f && rot.z < 350f)
rot.z = 45f;
transform.eulerAngles = rot;
I do this on LateUpdate() but have tried it on Update() as well with the same result, which is that if it rotates past 45 degrees, I make it equal 45 degrees but then it just stays there, the physics engine never seems undo it from this.
I'm not entirely sure how the physics engine works but why wouldn't it make my cube fall back below 45 degrees?
Any help would be greatly appreciated!
Thanks
P.S. I have the < 350f check in there because when the cuboid is moving on the flat the angle seems to go between 355ish - 0.5ish.
Your answer
Follow this Question
Related Questions
Is it possible to constrain an object's rotation in worldspace? 2 Answers
How to make a RigidBody not go into ground when tilted foward? 2 Answers
How does one constrain rotations of a CharacterController without a Rigidbody? 0 Answers
Rigidbody constraints not working with parent/child relationship 2 Answers
Rotate object towards target without influencing AddForce 0 Answers