Hello,
I am following N3K EN’s endless runner tutorials on Youtube. However, I could not move the character around. Here is my script:
using UnityEngine;
using System.Collections;
public class PlayerBehaviour : MonoBehaviour
{
private CharacterController controller;
private Vector3 moveVector;
private float speed = 5.0f;
private float verticalVelocity = 0.0f;
private float gravity = 12.0f;
// Use this for initialization
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
moveVector = Vector3.zero;
if (controller.isGrounded)
{
verticalVelocity = -0.5f;
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
//X - Left and Right
moveVector.x = Input.GetAxisRaw("Horizontal") * speed;
//Y - Up and Down
//Z - Forward and Backwards
moveVector.z = speed;
controller.Move(moveVector * Time.deltaTime);
}
}
Could anyone help me? I went through the tutorial numerous times but still it’s not working. I rewrote the script, too. Could this have something to do with a missing component or wrong setting?