When I hit w key in game, the player runs but only in place.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
float speed = 50.0F;
float rotationSpeed = 50.0F;
Animator animator;
// Start is called before the first frame update
void Start()
{
rb = this.GetComponent<Rigidbody>();
animator = GetComponentInChildren<Animator>();
}
// Update is called once per frame
void LateUpdate()
{
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
Quaternion turn = Quaternion.Euler(0f, rotation, 0f);
rb.MoveRotation(rb.rotation * turn);
animator.SetFloat("speedMuilt", translation);
if (translation != 0)
animator.SetBool("Idling", false);
else
animator.SetBool("Idling", true);
if (Input.GetKeyDown("space"))
{
animator.SetTrigger("Attacking");
}
if (translation != 0)
animator.SetBool("Idling", false);
else
animator.SetBool("Idling", true);
if (Input.GetKeyDown("w"))
{
animator.SetTrigger("Run");
}
}
}
