Hi! I have two kinematic objects, one of them is a player. How to make the player push the object?
When a collision is detected by Box2D you get one collision_response message and multiple contact_point_response messages. When your player script gets a contact_point_response message you need to move whatever object it is you are colliding with to simulate the push. Something like this:
function on_message(self, message_id, message, sender)
if message_id == hash("contact_point_response") then
local object_position = go.get_position(message.other_id)
-- move object along the collision normal
-- it could be that you need to change the + to a -
go.set_position(object_position + message.normal * message.distance, message.other_id)
end
end
2 Likes
Thanks, that helped!