Hi everyone!
Was trying to get my character moving in a top-down style using WASD keys and encountered an issue. Found one script on youtube posted in 2016, copy-pasted it into my project, but something doesn’t work quite well. The player character just moves with every input all the way to the end of nav mesh in the input direction, instead of, let’s say, controllable movement.
Could you please take a look and tell me what’s the issue?
Sorry, if the problem is simple and ridiculous, I’m kinda a newbee in this sphere and just trying to get into it.
Thanks in advance! The code is below:
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private Rigidbody PlayerRigidBody;
private Vector3 moveInput;
private Vector3 moveVelocity;
// Start is called before the first frame update
void Start()
{
PlayerRigidBody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput * moveSpeed;
}
void FixedUpdate ()
{
PlayerRigidBody.velocity = moveVelocity;
}
}