I find that the collision still exists after I handle the collision distance (according to Resolving kinematic collisions).
I also tried the Platformer template and added a print in message handler, and found it has the same problem.
I wonder whether it is a normal and acceptable situation that the collision will still be triggered even if the colission distance is 0, and whether it will heavily reduce the performance since it will send so many messages to game objects (that’s why I try to solve the continuous collision).
Thanks.
can you show us more of the problem? prints of the game objects would be nice, as well as the script
Actually the Platformer template behaves the same problem.
Just add print("collided")
in player.script
just like that:
local function handle_obstacle_contact(self, normal, distance)
if distance > 0 then
-- First, project the accumulated correction onto
-- the penetration vector
local proj = vmath.project(self.correction, normal * distance)
if proj < 1 then
-- Only care for projections that does not overshoot.
local comp = (distance - distance * proj) * normal
-- Apply compensation
go.set_position(go.get_position() + comp)
-- Accumulate correction done
self.correction = self.correction + comp
end
end
-- collided with a wall
-- stop horizontal movement
if math.abs(normal.x) > 0.7 then
print("collided")
self.wall_contact = true
self.velocity.x = 0
end
-- collided with the ground
-- stop vertical movement
if normal.y > 0.7 then
self.ground_contact = true
self.velocity.y = 0
end
-- collided with the ceiling
-- stop vertical movement
if normal.y < -0.7 then
self.velocity.y = 0
end
end
and when the game run and the player hit the wall, the print
will be excuted again and again
oh, i misunderstood. I thought you were talking about a trigger collision. But yeah, collisions work just like that it never stops triggering until you deactivate the component. Even if you stop handling it, other collisiont bodies will still collide with it. The trigger collision only checks whenever you enter and quit a collision, but the kinematic collision will always trigger. Box 2d has some quirks like that.
About performance: dont worry, this is SURELY not the type of thing to ruin a game. Unless you have bodies in the count of thousands, i assure you there wont be ANY performance problems. Defold is very tiny, bloat free and optimized. If it ever comes to be unoptimized - for whatever reason - come here or in our discord, wed be glad to help.
Thanks for your reply. So it is ok that the collision is still triggerring even if the distance is 0 and I don’t need to handle this for performance reason?
I’d say it’s as it should be. It’s also unlikely to never be exactly at 0 distance due to floating point precision.
nah, defold is probably the most performant you can get before you dive into pure code stuff like love2d/lovr. Even if you export to the web where theres no jit - yet (?) - it still is very performant.
Premature optimization is the root of all crunch development, the right time to start worrying about optimization is when your game starts to get stuttery or something like that (which will definetly take a lot specially in 2d games).