I have 2 mask objects next to each other. When I move the player by clicking, it lags at the edge of those objects.
This is my code
if message_id == hash("contact_point_response") then
if message.group == hash("bar") then
go.set_position(go.get_position() + message.distance * message.normal)
end
end
Have you enabled physics debug in game.project? This will draw the physics shapes and maybe give you a clue. Please give it a try and share another gif.
Ok, so in the gaps between the shapes we can see that you are getting pushed back. What’s your game going to look like? Can you have one large shape spanning several pieces of ground? Or maybe ignore the horizontal component of the collision if the vertical is greater? It depends on your levels really.
@britzl My game is an endless runner with bars go up and down. When user touches the screen, the player will move forward horizontally. But the current bar that player is standing on has to be next to the next bar. I want the player slips smoothly from a bar to another. If the next bar is higher or lower than the current bar, user will lose. That why I test bars next to each other and move the player
if message_id == hash("contact_point_response") then
if message.group == hash("bar") then
local normal = message.normal
if math.abs(normal.y) > math.abs(normal.x) then
normal.x = 0
end
go.set_position(go.get_position() + message.distance * normal)
end
end
@britzl the player are not getting pushed back now. But it is still standing higher than bars. Can I use this code to fix it? By the way, could you explain why you have to compare normal.x and normal.y? I do not understand it
if message.distance > 0 then
-- First, project the accumulated correction onto
-- the penetration vector
local proj = vmath.project(self.correction, message.normal * message.distance)
if proj < 1 then
-- Only care for projections that does not overshoot.
local comp = (message.distance - message.distance * proj) * message.normal
-- Apply compensation
go.set_position(go.get_position() + comp)
-- Accumulate correction done
self.correction = self.correction + comp
end
end