Contact points at intersections problem

Hi all,

I’m having an issue.

I have a character gameobject moving left (kinematic), the character walks across static ground gameobjects using contact point response to stop them falling through.

However, when the character reaches the edge of one ground gameobject it always stops walking for a second?

The ground objects line up perfectly, and I tried making them overlapping but the character still stops!

Maybe this is a bug?

Thanks.

I’m guessing by your issue that you’re getting a contact point with a normal pointing sideways?
What do you see when you print the messages?

Also, toggling the physics debug rendering might give some help (and makes it easier to take screenshots of your setup):

function init(self)
    msg.post("@system:", "toggle_physics_debug")
end

Perhaps the corners of the of the collision shapes are sideways?

Take a look at two examples:

In the second example I simply moved the left hand ground piece upwards in the editor before building.

Here’s the code I’ve got on the character:

local group_geometry = hash("geometry")
local msg_contact_point_response = hash("contact_point_response")

function init(self)
	self.gravity = -10
	self.ground_contact = false
	self.direction = "right"
	self.correction = vmath.vector3()
end

function update(self, dt)
	local currentpos = go.get_position()

	if self.ground_contact == false then
		newpos = currentpos + vmath.vector3(0,self.gravity,0)
	end
	
	if self.ground_contact == true and self.direction == "right" then
		newpos = currentpos + vmath.vector3(1,0,0)
	end
	
	if self.ground_contact == true and self.direction == "left" then
		newpos = currentpos + vmath.vector3(-1,0,0)
	end
	
	go.set_position(newpos)
	
	self.correction = vmath.vector3()
	self.ground_contact = false
end

local function handle_geometry_contact(self, normal, distance)
	local proj = vmath.dot(self.correction, normal)
	local comp = (distance - proj) * normal
	self.correction = self.correction + comp
	go.set_position(go.get_position() + comp)
	self.ground_contact = true
end

function on_message(self, message_id, message, sender)
	if message_id == msg_contact_point_response then
		if message.group == group_geometry then
			handle_geometry_contact(self, message.normal, message.distance)
		end
	end
	
	if message_id == hash("collision_response")then
		if message.group == hash("wall") then
			if self.direction == "left" then
			 	self.direction = "right"
			 else
			 	self.direction = "left"
			 end
        end
	end
end

Strange, I cannot seem to reproduce this behavior. I tested your script, with a character that has a kinematic box shape (it looks like your is too?)

Perhaps if you turn on the debug physics rendering and take a screenshot, it might yield some insight.

Yes, please turn on physics debug either by checking the box in game.project or by posting a message like @jcash showed in a previous reply. Post some screenshots or a gif when reproducing the issue with physics debug enabled.

1 Like