I am creating a platformer that uses lifts throughout the game; these lifts have all been created using animations; though I have started having concerns that I have 50+ lifts throughout game, and that seems like a lot of animations. I startd to wonder if there was a better way…
I am thinking a loop like follows would negate any unnecessary animation overhead, but I am not 100% sure if that is something I am making up. I have always believed animations to be expensive.
function Awake(){
start = transform.position;
myTransform = transform;
move();
}
function move(){
while(moved!= false){
if(direction == "x"){
for(i = myTransform.position.x; i<= start.x+maximum; i+= Time.deltaTime*speed){
yield;
myTransform.position.x = i;
}
myTransform.position.x = start.x+maximum;
yield WaitForSeconds(2);
for(j = myTransform.position.x; j>= start.x; j-= Time.deltaTime*speed){
yield;
myTransform.position.x = j;
}
myTransform.position.x = start.x;
yield WaitForSeconds(2);
yield;
}
}
}
I’m using this code now on a few objects, behaves well.
Where I once worked I asked the animation and code team this exact question and was told always to code movement if I could, but I just wanted a communities opinion before I do this as it’s an extensive change.
Thanks, Bobblehead.