How to reference contact point response variables?

I’m trying to have my player character interact differently with different collision groups and collision objects at specific locations, but i’m not sure how to reference the variables in “contact_point_response” such as on the line of code below so that I can code different responses.
image
How do I do this?

just use the collision group name

if message_id == hash("contact_point_response") then
  if message.other_group == hash("groupname") then -- change groupname
    ...
  end
end
1 Like

Do you know how I would specify the location of the collision object?
At the moment i’m specifying the location of the player but I feel that in some cases it would be easier to specify the location of the collision object tile itself.

quick and easy :slight_smile:

message.other_position

With message.other_position, what would the location be for my tiles?
Would it register the center or anywhere within the 16x16 tile?

No, other_position will not give you the tile, but the position of the entire tilemap component. You can easily calculate it though:

local TILE_SIZE = 16

function on_message(self, message_id, message, sender)
	if message_id == hash("contact_point_response") then
		local tx = math.floor((message.position.x - message.other_position.x) / TILE_SIZE)
		local ty = math.floor((message.position.y - message.other_position.y) / TILE_SIZE)
		print(tx, ty)
	end
end

You may need to offset tile by 1. Try it yourself and see!

3 Likes