- Home /
[CLOSED] How could i use 2 or more Prefabbed .FBX model animations in my "Chase Player" Script?
this is a small problem i am encountering but can't seem to find the right way to do it.
at the current moment i have two animations that i have prefabbed called "deathStalkerIdle" and "deathStalkerRun" each prefab is a rigged model of the AI.
when my player comes into range the model, it will advance towards the player and when a certain length away, it will stop.
to the point: Play the running prefab animation when player is in range. and play idle prefab animation when player is not.
this is a script i found on the unity forum, which is much better than the one i did. I forgot who wrote this, but i will give them credit for the script.
// This is the object to follow
var leader : Transform;
// This is the object which follows
var follower : Transform;
// This is the speed with which the follower will pursue
var speed : float = 2.0;
// This is the range at which to pursue
var chaseRange : float = 10.0;
// This is used to store the distance between the two objects.
private var range : float;
var runPrefab : Rigidbody;
function Update(){
// Calculate the distance between the follower and the leader.
range = Vector3.Distance( follower.position,leader.position );
if ( range <= chaseRange )
{
// If the follower is close enough to the leader, then chase!
follower.LookAt(leader);
follower.Translate( speed * Vector3.forward * Time.deltaTime);
} // End if (range <= chaseRange)
else {
// The follower is out of range. Do nothing.
return;
} // End else (if ( range <= chaseRange ))
} // End function Update()
if anyone has any ideas on how i can do this, i will greatly appreciate it.
Thanks
Ownerfate
i can close this question down because, yesterday i just used animations, triggers and instantiate scripts to get the effect i needed.
Answer by ownerfate · Feb 20, 2015 at 02:24 PM
Good god, i forgot about this ... beast of a horrid script...
i scrapped that whole system and brought in one that was MUCH smoother and doesn't include prefabbing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Importing a model without it becoming a prefab 3 Answers
How to create prefab from a GameObject variable in class? 0 Answers
Updating a prefab fbx or animation while using version-control is broken 4 Answers
Unity FBX to Prefab Position reseting 1 Answer
Can't add components to imported FBX 1 Answer