So, I’m making a simple pong game to learn the ins and outs of Defold.
So far I’ve made the ball move, ‘built’ the field and added paddles that respond to user input.
My next challenge was to make the borders collide with the ball and paddles, but I ran in a problem.
Using an example I wrote a piece of code that would check for collision, but regardless if it collided with the borders it didn’t seem to receive a message(I checked the mask and group for both of the objects), but it did get one for a collision with the ball:
function on_message(self, message_id, message, sender)
--check for collision
if message_id == hash("contact_point_response") then
print(sender)
end
end
I wanted to then check if the paddle collided with the ball or the border to make it respond only to the border.
The next thing I did was to try and implement the triggers that would count score, and I got a message when the ball hit them, but I didn’t find a way to check which side was hit.
if message_id == hash("trigger_response") then
if message.enter then
if sender == hash("[main:/level_pong/border#edge_red]") then
print("Score Red!") -- <^ change this if you change project structure!!!
elseif sender == hash("[main:/level_pong/border#edge_green]") then
print("Score Green!")
end
end
end
How would I check the sender id properly, and is there a piece of documentation that would explain the attributes of the message’s parameters? (e.g.: message.enter)