- Home /
Physics.Simulate not working in Editor (or Play Mode)
In my scene I have a bunch of Rectangles, 2D Sprites with RigidBody and BoxCollider2D components, all stacked up together such that their collider boxes overlap each other. When I enter play mode, rectangles expectedly move away from each other, until there's no overlap. I tried to mimic this effect in the Editor, but for some reason it's not working for me. I followed this stackoverflow answer , it doesn't seem to work neither in the Editor nor in play mode (i tried to run multiple Simulate commands at once, i.e multiple Physics.Simulate with a step of Time.FixedDeltaTime, pretty sure thats a valid way of doing that)
The end goal is to be able to quickly simulate multiple physics steps at once, until the rectangles aren't moving/colliding. I run this method in the editor through a custom editor class:
public void SimulatePhysics()
{
for (var i = 0; i < steeringTicks; i++)
{
Physics.autoSimulation = false;
Physics.Simulate(Time.fixedDeltaTime);
Physics.autoSimulation = true;
}
}
All rectangles have rigidbodies, 2d colliders, body type is dynamic, sleep mode is "never sleep", collision detection is discrete, interpolate is none. Not sure if changing any of those would solve my problem, as the automatic simulation runs fine in play mode.
Your answer
Follow this Question
Related Questions
Can I have a single rigidbody2d that acts as both collider and trigger? 1 Answer
2D collisions not showing all contact points 0 Answers
Bullet Trail not destroying on collision 0 Answers
How to tell if a 2D object is in a certain area 2 Answers
How can I make sure triggers or collisions are never skipped even for high speeds? 2 Answers