So I’ve been making a 1st person controller in unity. I want to make the player move in relation to where I am looking at (basically, on the local coordinates), however, when I run it, it keeps moving at the same direction(the global coordinates). Can somebody give me some help on the matter?
here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveAround : MonoBehaviour
{
public CharacterController controller;
public float speed = 10;
void Update()
{
float Xinput = Input.GetAxis("Horizontal");
float Zinput = Input.GetAxis("Vertical");
Vector3 move = transform.right * Xinput + transform.forward * Zinput;
controller.Move(move * speed * Time.deltaTime);
}
}
i may be wrong, but i think local means in relation to the parent object and global is the scene.
if that is the case you want to be moving on the global anyways.
your controller.transform.right idea didn’t help, but I found that, if I made an object with my look around code (only horizontal portion) and then referenced it in the moving code, it actually worked, so thanks a bunch friend!