|Topic was automatically imported from the old Question2Answer platform.
I have a sprite on a sheet that has different size depending on the frame. Is there a way to have collision shape change depending on what frame it is on?
Some game engines allow a black and white image to be added to a sprite sheet as a collision mask. Is there anything like this in Godot?
I don’t know if there is an easy way to do it, but if you manage to do it, maybe it will be fine for static objects… but issues could happen on kinematic or rigidbodies. Physics engines rarely like their shapes to change or teleport into something else every frame.
Zylann | 2018-04-17 17:58
Darn. How do you handle a sprite collision when the character ducks and the collision shape needs to be smaller?
ondesic | 2018-04-17 18:13
I didn’t say it doesn’t work, just that there might be issues.
For kinematic chars you could try, but probably will be more efficient to set a collision shape per state, and not per frame (because you could have many frames for the animation)
Zylann | 2018-04-17 18:41
So how would you do that? Do you create multiple shapes and programmatically disable them as needed?
ondesic | 2018-04-17 19:09
Yes. To do what you asked, you would need to do that anyways first before being able to do that per frame (which is basically what it would do)
Zylann | 2018-04-17 21:01
I have exactly the same problem:
KinematicBody2D player needs a different collision rectange when it walks VS when it ducks VS when it swims. I have a separate
CollisionShape2D for each state, and I use
CollisionShape2D.disable so that only one of them is active at a time. It works, except, because the effective collision shape changes suddenly, it might will overlap with another collision shaple (like a wall tile or enemy), and the physics engine doesn’t allow that. So usually it automatically teleports the character on some direction to get rid of the overlap. This teleportation sometimes leads to comical glitches, since the engine can’t know what makes sense gameplay wise. Worse, sometimes it lefts the player stuck inside the wall… There must be a common way of handling this… So I also wonder what’s the best practice.
hdc128 | 2018-04-22 12:59
Since then I have realized that this kind of problem pops up in an even more basic case: if you flip a
KinematicBody2D (like as the actor moves left or right), its
CollisionShape2D isn’t flipped by Godot. (So it’s better be symmetrical…) If it would be flipped, they run into the same issue (changing collision shape, might overlaps with another suddenly). Now it starts to be absurd… I must be blind or something.
hdc128 | 2018-04-22 14:56