B
B
Bruh_Bruh2020-09-23 18:56:41
Unity
Bruh_Bruh, 2020-09-23 18:56:41

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

1 answer(s)
D
DanielMcRon, 2020-09-23
@Bruh_Bruh

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 question

Ask a Question

731 491 924 answers to any question