i have a model of a dog. while animated in my scene i get 60 fps or more.
now i add a mesh collider, and a ridgid body, and this script
private var leader : Transform;
private var follower : Transform;
var speed : float = 6.0;
var chaseRange : float = 55.0;
var midRange : float = 30.0;
var closeRange : float = 7.0;
private var range : float;
private var walking = false;
private var running = false;
function Start()
{
leader = GameObject.Find("PlayerController").transform;
follower = GameObject.Find("dog").transform;
// Set all animations to loop, and stop any that are playing
animation.wrapMode = WrapMode.Loop;
animation.Stop();
}
function Update(){
// Calculate the distance between the follower and the leader.
range = Vector3.Distance( follower.position,leader.position );
if ( range <= chaseRange range >= midRange) {
if (!running) {
running = true;
walking = false;
animation.CrossFade("run");
}
// If the follower is close enough to the leader, then chase!
follower.LookAt(leader);
follower.Translate( (speed * 3.15) * Vector3.forward * Time.deltaTime);
}
else if ( range <= midRange range >= closeRange){
if (!walking) {
running = false;
walking = true;
animation.CrossFade("walk");
}
// If the follower is close enough to the leader, then chase!
follower.LookAt(leader);
follower.Translate( speed * Vector3.forward * Time.deltaTime);
}
// We have gotten too close !
else if (range >= closeRange) {
if (walking || running){
walking = false;
running = false;
follower.LookAt(leader);
animation.CrossFade("idle");
}
}
// Out of range?
else {
if (walking || running){
walking = false;
running = false;
follower.LookAt(leader);
animation.CrossFade("idle");
}
}
}
the script is so that the dog will run towards the camera, then slow down , and eventually stop. the dog follows you around.
the script runs fine i get regular fps when not focused on the dog,
but when i do look at the dog, and only when the script is running, my fps drops to around 15. that is way to low!
i set all small objects to a separate layer, and cull them early. i also use compression on anything i can think of, and also try and code things properly. but as soon as i interact with one npc the game died from low framerate and only while looking at it. if i look at the dog animation without the extra components making it an npc then i dont get the framerate drop.
any ideas?