Question by
robertolaudrup · Aug 02, 2016 at 07:29 PM ·
animationscript.
Script + How to setup animator controller
Someone can make a Script of this? and the setup of the animator controller? https://www.assetstore.unity3d.com/en/#!/content/66083
The animation never works fine when I put my script (i'm noob)
Thank you very much
My script:
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour { public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLenght = 100f;
void Awake()
{
floorMask = LayerMask.GetMask("Floor");
anim = GetComponent<Animator>();
playerRigidbody = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Move(h, v);
Turning();
Animating(h, v);
}
void Move (float h, float v)
{
movement.Set(h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.MovePosition(transform.position + movement);
}
void Turning()
{
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast(camRay,out floorHit, camRayLenght,floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
}
void Animating(float h, float v)
{
bool walking = h != 0f || v != 0f; //true
anim.SetBool("IsWalking", walking);
}
}
Comment
Your answer
