- Home /
Adding rigidbodies to enemies is lagging out the game?
I'm making a 2d game where there are enemies that follow you around in this forest. There are 300 trees, and the player and the enemies both need to collide with the trees. The player, trees, and enemies all have capsule colliders, and the player has a rigidbody while the trees do not. I have a script where the zombies follow the player that goes like this:`
public float speed;
private GameObject target;
void Start() {
target = GameObject.FindWithTag("Player");
}
void FixedUpdate() {
transform.LookAt(target.transform.position);
transform.position = Vector3.MoveTowards(transform.position,target.transform.position,speed*Time.deltaTime);
}`
It then works normally until the enemies start to spawn. If the enemies DON'T have rigidbodies, the game works fine, but they won't collide with the trees. When they DO, the game starts to lag out IMMENSELY. Also, it gives an error in the console when the , saying "Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually" Can someone help me?
Whenever the first enemies spawn it lags the game out, even if there is only one
Don't use FixedUpdate() for non-physics. This is not the root cause of a 1mob lags game, but generally don't do that.
I switched to a js script I found online that works a bit faster, but it still lags. Is there any way I could remove the rigidbody and just have the enemy turn around when it collides with a tree?
See: http://answers.unity3d.com/questions/7841/what-does-the-compute-mesh-inertia-tensor-failed-e.html
Try adding mesh collider to your zombie? If that doesn't work, please share your project and I'll have a look (if you don't $$anonymous$$d me looking at it ofc.)
Your answer
Follow this Question
Related Questions
How Do I Reduce Lag in my Networked Game? 5 Answers
Does collider size affect performance? 1 Answer
Multiplayer Rigidbody Vibration 2 Answers
Why does this simple follow script make my game lag? 2 Answers
MovePosition not as precise as Translate with Kinematic rigidbodies (example unitypackage included) 1 Answer