Flip/rotate game object with many children and collision (SOLVED?)

#1

Looks like this is a known bug (DEF-1117). Rotating y of the game object cause collision shapes to become upside down.

Is there any workaround for this?
Separating collider to different game object and moving them at the same time is not a quite practical solution I guess :confused:

go.set_rotation(vmath.quat_rotation_y(math.rad(180)))

3742

3 Likes

#2

Put sprites on sub GO and flip that instead of the parent (or flip the sprites directly).

3 Likes

#3

sub go do the trick, thank you @Pkeod

2 Likes

#4

What did your recent investigation result in @Mathias_Westerdahl? Was it more complex to fix than we initially thought?

0 Likes

#5

It was a bit more complicated than I initially thought. It requires some design/discussion with the team. But I want (and hope) to fix it this sprint or the next at least.

4 Likes

#6

Physics flip added in 1.2.161

1 Like

#7

Despite thinking it did work, I can now not get this to work on a Kinematic Tilemap. :cry:

This code:

go.set_rotation(vmath.quat_rotation_y(math.rad(180)))

Gives this change:

04 13

What am I doing wrong?

Minimal example: TilemapRotation.zip (26.4 KB)

0 Likes

#8

Is the above a Defold bug, or something in my code?

0 Likes

#9

Box2D cannot flip shapes, that is something we need to handle specifically (I.e we need to detect a new rotation, and alter the shape on the fly)
Rotation of tilemaps is not a request I recognize though.
We do have a ticket for rotating/flipping collision objects.

Edit: One reason it’s not trivial, is the question “how should it handle a rotation of 45degrees around Y?”
Since rotations are updated continously, we’ll need to alter the Box2D shape continously, which obviously is not ideal.

0 Likes

#10

Aha, all that makes sense.

I think the only way to change fixtures on the fly in Box2D is to remove and recreate them. I assumed the comment above meant that this had been implemented? If not, what does it mean?

I suppose you mean quaternion (magic) rotations? I just tested euler z rotations, and they work fine for a Tilemap with collision object tiles.

0 Likes

#11

It means there are excplicit functions for flipping the collision object:
physics.set_hflip, physics.set_vflip.
And, I think we just forgot to make sure they also handled tilemap collisions.

Yyes, it works fine if you rotate it in the Z plane, since the geometry is defined in the XY plane.
But in your request you mentioned rotating it in the XZ plane (i.e. around Y).
This is where it gets tricky.

1 Like