It looks like my game object is currently receiving a contact_point_response
message containing a horizontal contact point (assuming that’s what the debug arrows indicate) while walking along a flat surface, which causes the horizontal movement to be abrupt. The movement is fine while the game object is in the air as it isn’t colliding with any surfaces. Here’s an example screen recording of what is currently happening:
Mirror: https://forum.defold.com/uploads/default/original/3X/e/0/e0b23953077be7058e1499dbd07adf9057f0dfd1.mp4
Here is what the game object’s update function looks like:
function update(self, dt)
local target_speed = self.move_input * self.max_speed
local speed_diff = target_speed - self.velocity.x
local acceleration = vmath.vector3(0, self.gravity, 0)
if speed_diff ~= 0 then
if speed_diff < 0 then
acceleration.x = -self.move_acceleration
else
acceleration.x = self.move_acceleration
end
end
local dv = acceleration * dt
if math.abs(dv.x) > math.abs(speed_diff) then
dv.x = speed_diff
end
local v0 = self.velocity
self.velocity = self.velocity + dv
local dp = (v0 + self.velocity) * dt * 0.5
go.set_position(go.get_position() + dp)
self.correction = vmath.vector3()
self.move_input = 0
self.ground_contact = false
end
Here’s what the function that handles collision detection looks like:
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
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)
if normal.y > 0.7 then
self.ground_contact = true
end
proj = vmath.dot(self.velocity, normal)
if proj < 0 then
self.velocity = self.velocity - proj * normal
end
end
What might be causing this?