Different collision shape for each animation image

Is there a way to change collision shape while the animation is going on? My character is swinging an axe and I want to know if it is possible to change the collision shape as the axe moves.

No, the collision shape can’t really be modified. You can have multiple shapes and enable and disable them as needed though. And we will very soon release support for uniform scaling of collision shapes. It might help in your case?

1 Like

Are polygon shape collisions coming in the near future ?
i think that might be helpful in this case .

It’s actually already supported but a bit clunky to work with: https://defold.com/manuals/physics/#convex-hull-shape

2 Likes

How do I disable and enable different collision shapes mid-animation? I tried but it enables itself too early.

What did you try? Can you share the code?

function on_input(self, action_id, action)
--attacking motion
if action_id == hash("touch") and action.pressed then 
	msg.post("#sprite", "enable")
	if self.attacking == nil then
		sprite.play_flipbook("#sprite", "attack", anim_done)
		if sprite.image == hash("axe-13") or hash("axe-14") or hash("axe-15")then
			if self.right == true then 
				msg.post("#co_right", "enable")
			elseif self.left == true then
				msg.post("#co_left", "enable")
			end
		end
		self.attacking = true
		
	end
end

The documentation states “The image used when rendering the sprite.”. It’s not the best of description since what you get is the “atlas”/“tilesource”.

And even if the property referred to an individual image in the atlas there’s a problem with your conditional check:

if sprite.image == hash("axe-13") or hash("axe-14") or hash("axe-15") then

I’m guessing that you want to check is if sprite.image is one of “axe-13”, “axe-14” or “axe-15”? If that is indeed true then you need to write your check like this:

if sprite.image == hash("axe-13") or sprite.image == hash("axe-14") or sprite.image == hash("axe-15") then

What you could do is to use the normalised flipbook cursor: https://defold.com/ref/stable/sprite/#cursor