Player movment: height and straight besides normal xz axis?


I 've met the situations:

1 when i move my player in xz-plane, after awhile the y-position starts changing?

2 when i try to move my player in xz-plane and i cross the plane (not along x- or z- axis), i can not move it in straight line forward?

I 'm moving via a script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;

public class bootcontroller : MonoBehaviour {
public Rigidbody rb;
public transform ;
public float speed = 17;
//good test script

Vector3 rotationRight = new Vector3(0, 30, 0);
Vector3 rotationLeft = new Vector3(0, -30, 0);
Vector3 forward = new Vector3(1, 0,0);
Vector3 backward = new Vector3(-1, 0, 0);
void FixedUpdate()
    if (Input.GetKey("up"))
        transform.Translate(forward/2 * speed * Time.deltaTime);
    if (Input.GetKey("down"))
        transform.Translate(backward/2 * speed * Time.deltaTime);
    if (Input.GetKey("right"))
        Quaternion deltaRotationRight = Quaternion.Euler(rotationRight * Time.deltaTime);
        rb.MoveRotation(rb.rotation * deltaRotationRight);
    if (Input.GetKey("left"))
        Quaternion deltaRotationLeft = Quaternion.Euler(rotationLeft * Time.deltaTime);
        rb.MoveRotation(rb.rotation * deltaRotationLeft);


HI @RobSl,

did you try putting constraint on your Rigidbody component? Maybe it’s enough?

Hope will do!

Hi privatecontractor,

I tried your solution, but the problem still exists. The strang thing is when i move the player to an y-level of 10 or more, the problem is solved.

Thx for your reply,