#pragma strict
var speed : float = 10.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var runspeed : float = 20.0;
var lookAt : GameObject;
var rotateSpeed : float = 8.0;
var dampTime : float = 3;
var cameraRoot : Transform;
private var horizontalSpeed : float;
private var forward : Vector3 = Vector3.forward;
private var moveDirection : Vector3 = Vector3.zero;
private var isfight : boolean = false;
private var right : Vector3;
private var movespeed : float = 0.0;
private var canrun : boolean = false;
private var canclimb : boolean = false;
private var canjump : boolean = true;
function Start ()
{
}
function Update ()
{
var animator = GetComponent(Animator);
var controller : CharacterController = GetComponent(CharacterController);
animator.SetBool("isgrounded",controller.isGrounded);
forward = cameraRoot.transform.forward;
right = new Vector3(forward.z, 0, -forward.x);
var hor = Input.GetAxis("Horizontal");
var ver = Input.GetAxis("Vertical");
var targetDirection : Vector3 = (hor * right) + (ver * forward);
var horizontalVelocity : Vector3 = controller.velocity;
horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z);
horizontalSpeed = horizontalVelocity.magnitude;
horizontalSpeed = Mathf.Clamp(horizontalSpeed,0,1);
if (controller.isGrounded)
{
if (targetDirection != Vector3.zero)
{
moveDirection = Vector3.Slerp(moveDirection, targetDirection,10 * Time.deltaTime);
moveDirection = moveDirection.normalized;
var targetRotation = Quaternion.LookRotation (moveDirection);
targetRotation.x = 0;
targetRotation.z = 0;
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotateSpeed * Time.deltaTime);
animator.SetFloat("direction",0,dampTime,0.2);
if (isfight)
{
var targetRotation2 = Quaternion.LookRotation (lookAt.transform.position - transform.position);
targetRotation2.x = 0;
targetRotation2.z = 0;
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation2, rotateSpeed * Time.deltaTime);
animator.SetFloat("direction", Mathf.Atan2(hor,ver) * 180.0f / 3.14159f,dampTime,0.2);
animator.SetFloat("direction2",1,dampTime,0.2);
}
}
else
{
moveDirection = Vector3.zero;
}
if (Input.GetButtonDown("Jump") canjump)
{
animator.SetBool("jump",true);
moveDirection.y = jumpSpeed;
}
else
{
animator.SetBool("jump",false);
}
}
if ((Input.GetKey(KeyCode.G)))
{
animator.SetBool("grabweapon",true);
isfight = true;
canjump = false;
}
else if ((Input.GetKey(KeyCode.H)))
{
animator.SetBool("grabweapon",false);
isfight = false;
canjump = true;
}
if (Input.GetKey(KeyCode.LeftShift))
{
movespeed = runspeed;
animator.SetFloat("speed",horizontalSpeed*2,dampTime,0.2);
}
else
{
animator.SetFloat("speed",horizontalSpeed,dampTime,0.2);
movespeed = speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * movespeed * Time.deltaTime);
}
this simple script is firing the grounded bool of my animator even when the character is grounded, can someone help me understand why or help me how to fix this?