#This code is meant to turn the player character in the direction of movement but it doesn't work

1 messages · Page 1 of 1 (latest)

vital wasp
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovementPC : MonoBehaviour
{

    public float speed;


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(x, 0, z);
        movement.Normalize();

        transform.Translate(movement * speed * Time.deltaTime, Space.World);

        

        if(movement != Vector3.zero){
            transform.rotation = Quaternion.LookRotation(movement.normalized); 
        }

    }
}

It's always offset by 90 degrees to the left when I use it on my cube.

vital wasp
#

😭

noble blaze
vital wasp
vital wasp
#

It had the same issue

noble blaze
#

depends, what perspective is this game?

vital wasp
#

It's top down

noble blaze
#

2d?

vital wasp
#

So camera is up top and cube faces the direction it's moving

#

3D

noble blaze
#

or iso?

#

alright

vital wasp
#

Wait I'll grab a recording

#

Hold on

#

I added the long stick to the side so I can see the forward direction

noble blaze
#

You're cubes forward normal might be trasform.right, not .forward

vital wasp
#

Oh good idea

#

I'll try

#

All the rotations are 0

noble blaze
#

What do you mean by that?

vital wasp
#

As in, these are his default values

vital wasp
#

Or nope

#

There's no left

#

Waaaaaaaaaaaait

#

Is it possible that the stick is on his side and not his forward?

#

Omg

#

Hang on

noble blaze
#

It's possible, but shouldn't the forward be the direction it moves?

#

Now that I look at it, it doesn't seem to be, you should probably rotate it 90 degrees

vital wasp
#

I moved the stick to a different face by default

#

And now it's fine

#

I dont even know lmao

noble blaze
#

Alright, good 👍

vital wasp
#

Sorry for spending your time on that

#

lol