Hi,
I am trying to get the player to move slower when going backwards, I have the animations setup ready but he is going the same speed as when hes moving forward. How would I go about making him move slower when pressing “s”, thanks in advance.
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 600.0f;
public float turnSpeed = 400.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
void Start () {
controller = GetComponent <CharacterController>();
anim = gameObject.GetComponent<Animator>();
}
void Update (){
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimationPar", 1);
} else {
anim.SetInteger ("AnimationPar", 0);
}
if(Input.GetKey ("s"))
{
anim.SetInteger("AnimationPar", -1);
}
if (Input.GetButtonDown("Jump"))
{
anim.SetTrigger("isJumping");
}
else if(Input.GetButtonUp("Jump"))
{
anim.ResetTrigger("isJumping");
}
if(controller.isGrounded){
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}