#Movement

1 messages · Page 1 of 1 (latest)

next flicker
#

So I have this rotate script

    void Update()
    {
        turn.x += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
        turn.y = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
        xRotation -= turn.y;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        transform.localRotation = Quaternion.Euler(xRotation, turn.x, 0);
    }

And movement in my other script

    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);
    }

But my characther isn't walking forward according to where the camera is looking. It's just static, so forward side ways, is always the same. If I look to the left, it still walks the same way as before

lapis owl
#

First fix: don't multiply mouse input by deltaTime. It's a common error Brackeys made, we see it everyday here.
Actual fix, if these two scripts aren't on the same object, then in the movement script you need to take the transform.forward of the other object (the object the rotation script acts on)

next flicker
#

Ah okay thanks. I will try to do that.

He does say "And here we write deltaTime" a lot catlaugh

lapis owl
#

It's justified on most parts where you need to make code consistent across frame rates, but here it's unnecessary, as mouse input comes from a physical device, you move the same distance in real life at 15fps or at 60