- Home /
Quaternion + many collision meshes = intense lag?
Okay. I've been working on a simple open/close door script that I first found off of YouTube and modified a bit. I will post the code below.
Now one thing that has me utterly confused is why a particular Qaternion.lerp call is bringing my game from 60 fps down to 15 while the function is being called. My scene is very large; 55k trees, all with collision meshes, create the forested environment. If I remove the collision capsules from the trees via the terrain editor, the lag vanishes.
I'm a bit surprised because I would have thought that it's the onTriggerEnter and onTriggerExit that would be the costly bit of my script below--why whould Quaternion.lerp take into consideration collision meshes at all? The doors are not rigid bodies; nothing can (or is supposed to) stop them from opening.
Can anyone provide some insight as to what is happening and why? When I inevitably use AI calls with Quaternion.lerp or Quaternion.slerp, this issue will probably come right back.
// Smothly open a door
var smooth = 2.0;
var DoorOpenAngle = 90.0;
var DoorCloseAngle = 0.0;
var open : boolean;
var enter : boolean;
var moving: boolean;
var squeak : AudioClip;
var rotateTimerCurrent = 0;
var myTransform;
var target = Quaternion.Euler (0, DoorOpenAngle, 0);
var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
function Awake() {
myTransform = transform;
}
function Update (){
// rotate only if door is not fully open or closed, kept track via rotateTimerCurrent
if (rotateTimerCurrent > 0) {
if(open == true){
myTransform.localRotation = Quaternion.Lerp(myTransform.localRotation, target, Time.deltaTime * smooth);
} else {
myTransform.localRotation = Quaternion.Lerp(myTransform.localRotation, target1, Time.deltaTime * smooth);
}
//decrement rotation timer
rotateTimerCurrent = rotateTimerCurrent - Time.deltaTime*.1;
}
//check if player is trying to open the door
if(enter == true){
if(Input.GetKeyDown("f")){
open = !open;
audio.PlayOneShot(squeak);
rotateTimerCurrent = 40f;
}
}
}
//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
(enter) = true;
}
}
//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
(enter) = false;
}
}
Your answer
Follow this Question
Related Questions
Quaternions incorrect? 2 Answers
How to find a rotation of a child object 0 Answers
Quaternion rotation infinite? 1 Answer
How to get a line parallel to a plane? 1 Answer
how to apply overall rotation to collection of rotated objects 0 Answers