- Home /
Physics and prefabs
I've made a simple Airhockey game in Unity and now I want to train a ML agent to play the game. I've created a prefab that contains the complete playing area containing the field, the players and the puck and it works as intended when using only one instance of that prefab. The problem comes when we want to include multiple instances, (6+) of that prefab. Increase the instances of the prefab seems to causing glitches like the puck getting stuck.
What could be the cause of this and how do I fix it? Could it be due to the speed of the puck moving? If so, why isn't it causing problems when playing a game with only 1 instance of the prefab?
Do you have singletons on your prefab or on its children which you call from somewhere else? If you add more instances, does at least one of the instances work correctly and if so, is it the first or the last one added?
I'm not using any signletons. Second question. If it's only 1 or 2 instances, it behaves mostly normal but the more instances I add, the more unstable it becomes with the last instances added being worse than the first ones.
Where do you instantiate those prefabs in the scene? Are you sure that they don't overlap and that they aren't too far from the world origin? The further away from the origin the less precision you get due to floating-point numbers
I instantiate them around a path that's centered on the world origin. The farthest instance has as position -125, -10, 400
Apperently the problem was caused due multiplying the gravity in a script connected to the puck
Answer by Snipe76 · Jan 02, 2019 at 04:17 PM
Without any examples I can't clearly state the solution, but here are few options:
You are using Transform and Rigidbody together on the puck physics.
The instances are children of an object that cause them to freeze.
Your pucks have more colliders that conflict with each other.
Your Physics material is not set and it causes unexpected behavior.
You are using the Update() function for physics instead of FixedUpdate().
Here is a link about Unity Physics: Unity Physics Practices
If you can provide some physical examples I can provide a better solution.
Your answer
Follow this Question
Related Questions
Ignoring collisions without using physics layers 1 Answer
Physics Problem :Collision(When ball moves from one ground (made of cube) to another ) 0 Answers
Rigidbodies won't collide if mass difference is too high 0 Answers
How do I solve the Box Collider (3D) Edge / Corner Collisions problem? 5 Answers
Rigidbody is behaving abnormally when transformed manually 0 Answers