when i press the ‘w’ key my player moves at the right speed but when i press ‘w’ and ‘a’ or ‘d’ at the same time my play runs much faster
My Script:
using UnityEngine;
using System.Collections;
public class PlayerMovement2 : MonoBehaviour {
public GameObject Camera_Point;
public float movespeed = 5.0f;
public float MouseXSensitivity = 5f;
public float MouseYSensitivity = 3f;
public GameObject _player;
float verticalRotation = 0;
public float upDownRange = 60.0f;
public float verticalVelocity = 5f;
public float jumpSpeed = 5.0f;
CharacterController characterController;
Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
characterController = GetComponent<CharacterController>();
_player = gameObject;
}
void Update ()
{
PlayerMovement();
Animation();
}
void Animation()
{
anim.SetFloat("InputZ", Input.GetAxis("Vertical"));
anim.SetFloat("InputX", Input.GetAxis("Horizontal"));
}
void PlayerMovement()
{
float rotLeftRight = Input.GetAxis("Mouse X") * MouseXSensitivity;
transform.Rotate(0, rotLeftRight, 0);
verticalRotation -= Input.GetAxis("Mouse Y") * MouseYSensitivity;
verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange);
Camera_Point.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
//Player Movement
movespeed
float forwardSpeed = Input.GetAxis("Vertical") * movespeed;
float sideSpeed = Input.GetAxis("Horizontal") * movespeed;
verticalVelocity += Physics.gravity.y * Time.deltaTime;
if (characterController.isGrounded && Input.GetButton("Jump"))
{
verticalVelocity = jumpSpeed;
}
Vector3 speed = new Vector3(sideSpeed, verticalVelocity, forwardSpeed);
speed = transform.rotation * speed;
//Running
if (Input.GetKey(KeyCode.LeftShift))
{
movespeed = 15;
}
else
{
movespeed = 5;
}
characterController.Move(speed * Time.deltaTime);
}
}