(SOLVED) Can someone help me with kinematic collisions?

I am working on a 2D RPG. Right now, im trying to sort out interactions between the player and it environment (collisions) and I am having trouble with kinematic collisions. When the players collider meets with the environments (a rock) collider, they get stuck on each other. I know that the common way to fix this is to resolve the collision with some code but im a very new coder and have no clue how to do that. I decided to check out the RPG map sample, and it uses this chunk of code for its collisions:

elseif message_id == hash("contact_point_response") then
	-- simple collision solver
	local proj = vmath.dot(self.correction, message.normal)
	local comp = (message.distance - proj) * message.normal
	self.correction = self.correction + comp
	go.set_position(go.get_position() + comp)
end

end

This code doesn’t work for me and I don’t know why, or if it would even work in the first place. Can anyone help me with my issue?

What happens? Nothing?

They should also be on line of code in your update () function to reset the correction variable.

2 Likes

Without the code, the collisions don’t work (the player and the object pass through each other), but with the code the player and the object get stuck on each other.

I also believe it is in the update function, I don’t know if this is what you mean

self.correction = vmath.vector3()

I think tweaking this code would probably make it work but I don’t know how to go about that.

Ok, so I did some random tinkering and I changed self correction from
self.correction = self.correction + comp

to

self.correction = self.correction + comp + comp

Then I changed
go.set_position(go.get_position() + comp)

to

go.set_position(go.get_position() + self.correction)

For some reason this makes it so the player does not stick, but its very bouncy and spammy when it does come in contact. For now this will work but I have no clue how to fine tune it in the furture.

I would recommend that you read the following section of the physics manual:

Thanks!