How to work with physics normal and distance (SOLVED)

#1

I am working with physics. I use the code in this section to push the chicken back when it collides with the fences.
current
Because I have 2 shapes on the chicken 1 for the head and 1 for the body, the chicken stops at the head.
expect
I want it to stop at the body like the second image
This is my code

function on_message(self, message_id, message, sender)
  -- Handle collision
  if message_id == hash("contact_point_response") then
    local newpos = go.get_position() + message.normal * message.distance
    go.set_position(newpos)
  end
end
0 Likes

#2

Use one collision object for the head that isn’t masked with the fence and use one collision object for the body that is masked with the fence.

0 Likes

#3

It worked. Thank you @britzl

0 Likes