Hey Defolders! I’m new to Defold and am trying to make a simple platformer as my study project.
I ran into a problem: when i set the collision shape to tilemap, it seems like the player sometimes (sometimes not) gets stuck in the tile borders or something like that and doesn’t respond to user input, thus does not move left and right. But, when i delete the tilemap collision shape and simply add a few box shapes everything works fine, that’s why i thought the problem is in tilemap collision shape.
1) Using tilemap collision object: (doesn’t work)
Properties of map collision object:
Properties of player collision object:
2)using simple box collision shape: (works)
Properties of map collision object:
Properties of player collision object in that case are the same as in the previous one
Here’s the whole script for the reference that I mostly composed of codes from different tutorials. I initially thought the issue might be in the script, but now I kinda think script is not the issue here.
function init(self)
msg.post(".", "acquire_input_focus")
self.moving = false
self.input = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.speed = 150
-- correction vector
self.correction = vmath.vector3()
end
function final(self) -- [7]
msg.post(".", "release_input_focus") -- [8]
end
function update(self, dt)
-- reset correction
self.correction = vmath.vector3()
local pos = go.get_position()
pos.y = pos.y - 200 *dt
if self.moving then
pos = pos + self.dir * self.speed * dt
end
go.set_position(pos)
self.input.x = 0
self.input.y = 0
self.moving = false
end
function on_input(self, action_id, action) -- [14]
if action_id == hash("left") then
self.input.x = -1
elseif action_id == hash("right") then
self.input.x = 1
end
if vmath.length(self.input) > 0 then
self.moving = true
self.dir = vmath.normalize(self.input)
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
-- Get the info needed to move out of collision. We might
-- get several contact points back and have to calculate
-- how to move out of all of them by accumulating a
-- correction vector for this frame:
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
end
end
Here’s also a link to my GitHub. It has two branches that represent both cases. I’m not sure if my git is at all usefull for understanding the problem, but i thought it might help:
Any ideas what might be wrong?
Thanks a lot in advance!