Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Character : MonoBehaviour {
- public float turnSpeed;
- Animator animator;
- Vector3 lookPos;
- bool onGround;
- // Use this for initialization
- void Start () {
- animator = GetComponentInChildren<Animator>();
- }
- // Update is called once per frame
- public void Move (float forward, float turn, bool walk, Vector3 lookPos) {
- this.lookPos = lookPos;
- transform.Rotate(0, turn*turnSpeed*Time.deltaTime, 0);
- forward *= (walk ? 0.5f : 1);
- rigidbody.angularVelocity = Vector3.zero;
- animator.SetFloat("Forward", forward, 0.1f, Time.deltaTime );
- animator.SetFloat("Turn", turn, 0.1f, Time.deltaTime );
- animator.applyRootMotion = onGround;
- onGround = false;
- }
- void OnCollisionStay( Collision c )
- {
- foreach ( ContactPoint p in c.contacts )
- {
- Vector3 localP = transform.InverseTransformPoint( p.point );
- if (localP.magnitude < (collider as CapsuleCollider).radius)
- {
- onGround = true;
- }
- }
- }
- void OnAnimatorIK(int layerIndex)
- {
- animator.SetLookAtWeight(1, 0.2f, 2.5f);
- animator.SetLookAtPosition( lookPos );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment