Physics: How to re-position/rotate an existing compound object

Hi all!

I have issues placing an existing physics body (body.position..., body.rotation...) in the scene after it was set up with its impostors (like bringing a race car back on track or so). How is it supposed to be done? For me, weird things do happen:

  • rotation is not respected
  • the object receives spooky angular velocity (only Cannon)
  • Oimo looses all it’s physics capabilities?

I changed the common physics sample a bit to show the issue: https://playground.babylonjs.com/#K5T17W#1

Hope for help,

. J

Adding 2 physics masters : @RaananW and @Cedric :slight_smile:

This can be fixed by moving your meshes at the desired position before.
https://playground.babylonjs.com/#K5T17W#2
It works fine with Oimo and Ammo as well.
TBH, I don’t know exactly why it’s happening after moving the root or why setting the velocity/torque to 0 doesn’t reset it properly.

Yes @Cedric, before works, that’s what I did in my PG, just commented out.

The problem is before can be only done once … before.

What about a racecar constructed of a couple of meshes and impostors (and collision listeners on impostors and and and…). Once the car crashed, it needs to be set back in the racetrack.
Sounds like a pretty common use case to me.

Disposing and re-constructing the impostors seems to be a viable way to go. Like so: https://playground.babylonjs.com/#K5T17W#3

This seems pretty unelegant? How do you guys do that?

Nobody? @Cedric?

It’s pretty unelegant but I think it’s the best solution so far. Physics states will be cleared and I’m not sure it’s really a performance issue. Did you try it already?

1 Like

Yes @Cedric, tried it, that works. Just wonder that nobody else runs into that.

I’ll go for it that way now, thank you very much,

. J

1 Like