Collision objects problem! (SOLVED)

I have the next scene:

There are 2 collision objects, BOX[KINEMATIC] and MAN[STATIC], which shoud colide, and print the message in console…but I don`t work…help me please to understant the error!!!

grounds = {
			"ground1","ground2","ground3",
			"ground6","ground5","ground4",
			"ground9","ground8","ground7",
			"ground12","ground11","ground10",
			"ground15","ground14","ground13",
			}
			
function init(self)
 self.speed = 2
end

function update(self)
	for index,element in pairs(grounds) do
		local position = go.get_position(element)
		local man_pos = go.get_position("man")
		position.x = position.x - self.speed
		man_pos.x = man_pos.x + 0.3
		if position.x <= -50 then
			position.x = 1400 + ( position.x + 50)
		end
		if man_pos.x >= 1400 then
			man_pos.x = 20
			go.set_position(man_pos,"man")
		end
		go.set_position(man_pos, "man")
	end			
end

--Here I try to detect the colision
function on_message(self, message_id, message, sender)
    if message_id == hash("collision_response") then
		print("Colision detected!")
    end
end
1 Like

Ok, some things to help you debug:

  1. Toggle physics debug in game.project. This will show the collision components and any contact points.
  2. Make sure the BOX has a collision mask that is matching the group you have set on MAN, and vice versa. Read more about groups and masks here.
1 Like

For MAN I set the group “player”, the mask “world”, and for BOX I set the group “world”, the mask “player”…but still don`t work…help me please

Are the game objects scaled? There is an issue with this currently: Physic body scale issue? (DEF-521)

Could you run your game with “physics debug” enabled, as Björn suggested? :slight_smile: Then take a picture so we could have a look.

How to run the game with “physics debug” enabled ?

In your game.project file, there is a section for physics, with a checkbox for debug;

1 Like

Open game.project, scrolll to Physics, check the Debug checkbox and run your game.

Do you get any “Colision detected!” printed when you run?

I wonder if setting the position of your “man” each frame has something to do with it. (go.set_position(man_pos, "man"))

I did not get any message printed…but I got a WARNING:DLIB: Failed to send announce message (-22)

Have you attached the script to the “man” game object?

I tried to set up something similar to you locally and I get the print “Colision detected!”. Like this:


My man.script:

--Here I try to detect the colision
function on_message(self, message_id, message, sender)
    if message_id == hash("collision_response") then
		print("Colision detected!")
    end
end

Could you show us your collection setup? Do you get any errors in the output console?

Your both object are kinematic ?

My “man” object is static, and the “box” object is “kinematic”.

hallelujah…My script file was not created in the MAN object…now I created the script file in the MAN game object…and all work good

2 Likes

Haha awesome! Marking this as solved! :slight_smile: