Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Character : MonoBehaviour {
- public float moveSpeed;
- Animator animator;
- bool onGround;
- // Use this for initialization
- void Start () {
- animator = GetComponentInChildren<Animator>();
- }
- // Update is called once per frame
- void FixedUpdate () {
- bool walk = Input.GetKey(KeyCode.LeftShift);
- float v = Input.GetAxis("Vertical");
- float h = Input.GetAxis("Horizontal");
- v *= (walk ? 0.5f : 1);
- rigidbody.angularVelocity = Vector3.zero;
- animator.SetFloat("Forward", v, 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;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment