View difference between Paste ID: MMfV7QG2 and XFzWaTA5
SHOW: | | - or go back to the newest paste.
1
using UnityEngine;
2
using System.Collections;
3
4
public class Character : MonoBehaviour {
5
6
	public float moveSpeed;
7-
	public float turnSpeed;
7+
8
	Animator animator;
9
	bool onGround;
10
	
11
	// Use this for initialization
12
	void Start () {
13
	
14
		animator = GetComponentInChildren<Animator>();
15
		
16
	}
17
	
18
	// Update is called once per frame
19
	void FixedUpdate () {
20
	
21
		bool walk = Input.GetKey(KeyCode.LeftShift);
22
		
23
		float v = Input.GetAxis("Vertical");
24
		float h = Input.GetAxis("Horizontal");
25
		
26-
		float x = Input.GetAxis("Mouse X");
26+
27
		
28
		rigidbody.angularVelocity = Vector3.zero;
29
		
30-
		Vector3 moveDirection = v * transform.forward;
30+
31-
		moveDirection += h * transform.right;
31+
32
		animator.applyRootMotion = onGround;
33-
		transform.Rotate( 0, x * turnSpeed, 0 );
33+
34-
				
34+
35-
		Vector3 moveVelocity = moveDirection * moveSpeed;
35+
36-
		moveVelocity.y = rigidbody.velocity.y;
36+
37
	
38
	
39
	void OnCollisionStay( Collision c )
40
	{
41
		foreach ( ContactPoint p in c.contacts )
42
		{
43
			Vector3 localP = transform.InverseTransformPoint( p.point );
44
			
45
			if (localP.magnitude < (collider as CapsuleCollider).radius)
46
			{
47
				onGround = true;
48
			}
49
		}
50
	}
51
	
52
	
53
	
54
}