- Home /
Question by
mike29willems · Mar 25, 2019 at 02:19 PM ·
rotationrigidbodyquaternion
why can't my Rigidbody not rotate on slopes?
I have a scene where a bridge/slope connects the wall and ground so that the player can walk form the ground to the wall. But my player is not rotating anymore pls help. Btw I'am using a joystick for input that will give me a value between -1 and 1.
private void FixedUpdate()
{
h = Joystick.Horizontal;
v = Joystick.Vertical;
Move(h, v);
}
private void Move(float h, float v)
{
movement.Set(h, 0f, v);
movement = movement * speed * Time.deltaTime;
playerRig.MovePosition(transform.position + movement);
if (movement != Vector3.zero) //don't try to turn when standing still
{
Quaternion newRotation = Quaternion.LookRotation(movement, //transform.up);
playerRig.MoveRotation(newRotation);
// I also tried ->playerRig.AddTorque(transform.up * h * tor);
}
}
private void Update()
{
playerray = new Ray(transform.position + Vector3.up, Vector3.down);
Physics.Raycast(playerray, out hit, RayLengh)
Vector3 alignPlayerWithSurface = hit.normal;
transform.up = AlignPlayerWithSurface; //this worked
//(physics.gravity = hit.normal * -1; ) }
Comment
Answer by mike29willems · Mar 25, 2019 at 03:47 PM
After changing playerRig.moveRotation() to transform.rotation and putting 'transform.up = AlignPlayerWithSurface' in fixed update it worked, but idk why...
physics like raycast should always be in the fixedupdate they are not frame dependant, you should move the inputs to the update, and maybe the rigidbody interpolation wasnt enabled so it wasnt rotating with the rigidbody