Sprite To Sprite Collision Detection?

Hi,

Does Defold have built-in sprite to sprite collision detection?
Let us know, thanks!

Jesse

You need to have a look at the Physics manual and how to use the collision object component.

2 Likes

ok, thanks!

Ok, so I have 1 “Player” game object and 5 “Enemy” game objects.
All 6 game objects above have collision objects setup.
(Player is group “Player” and Enemies are group “Enemy”)

Little confused now:
How do I detect collisions between “Player” game object and the other 5 “Enemy” game objects?
Let us know, thanks!

Jesse

Make sure your collision groups and masks are set “both ends”:

Player
group: player
mask: enemy

Enemy
group: enemy
mask: player

Assuming you’re using kinematic objects, a message will be sent to both player and enemy scripts when a collision is occuring and can be checked for thus:

function on_message(self, message_id, message, sender)
    -- check for the message
    if message_id == hash("contact_point_response") then
        -- take action
    end
end
2 Likes

Does not work.
Also my collision shape in game objects is empty?
When I try to select a “collision shape” the dialog it empty?
All 6 game objects have a box collision shape.

This is already answered in the manual @sven linked. You need to actually read the manuals from start to finish and not read only the small sections which may be immediately useful to you.

2019-02-15%2015_18_54-Physics%20in%20Defold

That’s because you would need some related file in your project which had collision data which you evidently do not have.

You should try to make a stand alone collision test in its own small project so you can understand how all of the parts work before implementing it into a larger project.

2 Likes

Too complicated…
I implemented my own collision detection.