Nextrek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
using UnityEngine;
using System.Collections;
[AddComponentMenu("Mixamo/Demo/Root Motion Character")]
public class RootMotionCharacterControlMENS : MonoBehaviour
{
public float turningSpeed = 90f;
public RootMotionComputer computer;
public CharacterController character;
void Start()
{
// validate component references
if (computer == null) computer = GetComponent(typeof(RootMotionComputer)) as RootMotionComputer;
if (character == null) character = GetComponent(typeof(CharacterController)) as CharacterController;
// tell the computer to just output values but not apply motion
computer.applyMotion = false;
// tell the computer that this script will manage its execution
computer.isManagedExternally = true;
// since we are using a character controller, we only want the z translation output
computer.computationMode = RootMotionComputationMode.ZTranslation;
// initialize the computer
computer.Initialize();
// set up properties for the animations
animation["weightshiftidle"].layer = 0; animation["weightshiftidle"].wrapMode = WrapMode.Loop;
animation["walk"].layer = 1; animation["walk"].wrapMode = WrapMode.Loop;
animation["run"].layer = 1; animation["run"].wrapMode = WrapMode.Loop;
animation["boredidle"].layer = 3; animation["boredidle"].wrapMode = WrapMode.Once;
animation["jog"].layer = 3; animation["jog"].wrapMode = WrapMode.Loop;
animation["laugh"].layer = 3; animation["laugh"].wrapMode = WrapMode.Once;
animation["rally"].layer = 3; animation["rally"].wrapMode = WrapMode.Once;
animation["strutwalk"].layer = 3; animation["strutwalk"].wrapMode = WrapMode.Loop;
animation["talk"].layer = 3; animation["talk"].wrapMode = WrapMode.Once;
animation["wave"].layer = 3; animation["wave"].wrapMode = WrapMode.Once;
animation.Play("weightshiftidle");
}
void Update()
{
float targetMovementWeight = 0f;
float throttle = 0f;
// turning keys
if (Input.GetKey(KeyCode.A)) transform.Rotate(Vector3.down, turningSpeed*Time.deltaTime);
if (Input.GetKey(KeyCode.D)) transform.Rotate(Vector3.up, turningSpeed*Time.deltaTime);
// forward movement keys
// ensure that the locomotion animations always blend from idle to moving at the beginning of their cycles
if (Input.GetKeyDown(KeyCode.W) &&
(animation["walk"].weight == 0f || animation["run"].weight == 0f))
{
animation["walk"].normalizedTime = 0f;
animation["run"].normalizedTime = 0f;
}
if (Input.GetKey(KeyCode.W))
{
targetMovementWeight = 1f;
}
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) throttle = 1f;
// blend in the movement
animation.Blend("run", targetMovementWeight*throttle, 0.5f);
animation.Blend("walk", targetMovementWeight*(1f-throttle), 0.5f);
// synchronize timing of the footsteps
animation.SyncLayer(1);
// all the other animations, such as punch, kick, attach, reaction, etc. go here
if (Input.GetKeyDown(KeyCode.Alpha1)) animation.CrossFade("boredidle", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha2)) animation.CrossFade("jog", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha3)) animation.CrossFade("laugh", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha4)) animation.CrossFade("rally", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha5)) animation.CrossFade("strutwalk", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha6)) animation.CrossFade("talk", 0.2f);
if (Input.GetKeyDown(KeyCode.Alpha7)) animation.CrossFade("wave", 0.2f);
}
void LateUpdate()
{
computer.ComputeRootMotion();
// move the character using the computer's output
character.SimpleMove(transform.TransformDirection(computer.deltaPosition)/Time.deltaTime);
}
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|