Answer the question
In order to leave comments, you need to log in
Why does the motion script not work correctly?
Hello, I made this simple script to move an object forward using the character controller, but instead of moving forward, it moves along the Y axis. What's wrong? I didn't touch anything in the Input Manager.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private CharacterController character;
[SerializeField]
private float speed;
// Start is called before the first frame update
void Start()
{
character = GetComponent<CharacterController>();
speed = 5f;
}
// Update is called once per frame
void Update()
{
float z = Input.GetAxis("Vertical");
Vector3 move = transform.forward * z;
character.Move(move * speed * Time.deltaTime);
}
}
Answer the question
In order to leave comments, you need to log in
Transform.forward are local coordinates, maybe you have it moving correctly, but only in its own coordinates
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question