- Home /
Waypoints script: add 2 animations
Hello,
I'm doing a scene where some npc will moving randomnly in the piece around the player. In order to have this path, I used a waypoint script I found here: link text
The script works very well, but there's a little problem: I have only one animation on my npc, so he always walks, even in stop times when he reached a waypoint. My question is:
How can I add one more animation (idle) on stop times?
I made the npc character in Maya with an animation on it, so I imported the .mb file directly into my project to have the model, the rig and the animation, and then I imported an idle animation in a FBX file. What do I need to merge theses animations according to the movement of my character?
Here's my script I used for the waypoints, if you need it:
var accel = 0.8;
var inertia = 0.9;
var speedLimit = 10.0;
var minSpeed = 1.0;
var stopTime = 1.0;
private var currentSpeed = 0.0;
private var functionState = 0;
private var accelState : boolean;
private var slowState : boolean;
private var waypoint : Transform;
var rotationDamping = 6.0;
var smoothRotation = true;
var waypoints : Transform[];
private var WPindexPointer : int;
function Start ()
{
functionState = 0;
}
function Update ()
{
if (functionState == 0)
{
Accell ();
}
if (functionState == 1)
{
Slow ();
}
waypoint = waypoints[WPindexPointer];
}
function Accell ()
{
if (accelState == false)
{
accelState = true;
slowState = false;
}
if (waypoint)
{
if (smoothRotation)
{
var rotation = Quaternion.LookRotation(waypoint.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationDamping);
}
}
currentSpeed = currentSpeed + accel * accel;
transform.Translate (0,0,Time.deltaTime * currentSpeed);
if (currentSpeed >= speedLimit)
{
currentSpeed = speedLimit;
}
}
function OnTriggerEnter ()
{
functionState = 1;
WPindexPointer++;
if (WPindexPointer >= waypoints.Length)
{
WPindexPointer = 0;
}
}
function Slow ()
{
if (slowState == false)
{
accelState = false;
slowState = true;
}
currentSpeed = currentSpeed * inertia;
transform.Translate (0,0,Time.deltaTime * currentSpeed);
if (currentSpeed <= minSpeed)
{
currentSpeed = 0.0;
yield WaitForSeconds (stopTime);
functionState = 0;
}
}
I'm new to Unity and I'm not so good at scripting badly, so excuse my (probably) nooby question, but I'm stuck here and I don't know how to proceed to achieve this.
Thank you very much!
As you click on your character in the heirarchy, go and check the inspector , you should have the animation component attached. And in there can you see the list of animations listed one below each other, and the selected animation (current animation that will play) , if you have all these then its easy, you can change the animation at runtime.. e
Your answer
![](https://koobas.hobune.stream/wayback/20220613123407im_/https://answers.unity.com/themes/thub/images/avi.jpg)