My character moves extremely slow

The jumping and the rotation works fine although the character moves at a extremely slow speed, I tried to tweak the values of my code (even with high values like 3000) and the mass but nothing happens…
Heres the code:

public class scr : MonoBehaviour
{
    //Variables

    public float speed = 30000;
    private Rigidbody rb;
    private float midJump = 1;
 
    //Character Movement

    void Start()
    {
        rb = GetComponent<Rigidbody>();
     
    }
    void FixedUpdate()
    {
 

        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

     
        Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
        rb.transform.position += movement * Time.deltaTime * speed;

     

        //Character Jump


        if (midJump == 1 && Input.GetKeyDown(KeyCode.Space))
        {
            rb.velocity = new Vector3(0, 45, 0);
            midJump = 2;

        }
        else if (rb.velocity.y == 0)
            midJump = 1;
     

        //Character Rotation

        {
            if (Input.GetKeyDown(KeyCode.D))
                rb.MoveRotation(Quaternion.Euler(0, 90, 0));

            if (Input.GetKeyDown(KeyCode.A))
                rb.MoveRotation(Quaternion.Euler(0, -90, 0));

            if (Input.GetKeyDown(KeyCode.W))
                rb.MoveRotation(Quaternion.Euler(0, 0, 0));

            if (Input.GetKeyDown(KeyCode.S))
                rb.MoveRotation(Quaternion.Euler(0, 180, 0));





        }








    }
}

I think you need to use moveposition like you are doing the MoveRotation Link

1 Like

Just setting the transform position should work, not recomended on rigidbodies because of other rrasons, but should work.

1 Like

With MovePosition the rigid body doesnt even move and I cant jump :face_with_spiral_eyes:

I found the problem and it has a weird solution, since the speed variable is public I can change it on the inspector, but somehow the Speed on the inspector is 2, if I change it there the speed also does, but if I change in the code the speed is not affected :confused: Anyways now its solved thanks alot for the help guys!

2 Likes

Keep in mind that for any variables that you show in the inspector- whatever value you type in the inspector will always precede whatever you initialize the value to in your code.