What's the computationally cheapest way to move objects in a straight line?
Basically I need a highway with cars moving in a straight line on it. The only thing I need from the cars is to keep them moving in a straight line. What's the (resource) cheapest way to do this? I know I could use Unity's AI system, or a simple C# AddForce script. It is for an Android game which is why I need it to be as least-resource-consuming as possible.
Answer by Jessespike · Feb 02, 2016 at 10:44 PM
It depends. Do you need AI? Collisions? Way points? etc....
I would guess simply translating the position would be the fastest:
transform.position += transform.forward * speed * Time.deltaTime;
or maybe even velocity, if you know which way to go:
// public Vector3 velocity = new Vector3(1,0,0);
transform.Translate(velocity * Time.deltaTime);
No I don't need anything intelligent or collisions, I just need the cars to go in a straight line on a road (for visual appeal). It would be strange in a game to have a highway with no cars, or cars standing still. So I do need them to move. However, since they aren't important to the gameplay, I need them to not hog the CPU. Looks like your answer should do, thanks :)