as the GIF i uploaded ,
while the player hit the block "B1" , the player get "force" move up , dont know why , and how to fixed it ? what i want is just hit it do not overlap , keep what the player status . (also , collision type Freeze is NOT i need)
in my code :
function Player:collisionResponse(other)
if other:getTag() == BLOCK_TAG then
if self.hit_block_side then
return spr.kCollisionTypeSlide
end
return spr.kCollisionTypeSlide
end
end
and the player's update code , some like this :
-- update player postion
local _x, _y, collisions, numOfCollisions = self:moveWithCollisions(
self.x + self.dx,
self.y + self.dy
)
for i = 1, numOfCollisions do
local other = collisions[i].other
self.hit_block_side = false
if other:getTag() == BLOCK_TAG then
if (collisions[i].normal.y == 1) then
self.dy = 0 -- hit block bottom
end
if (collisions[i].normal.y == -1) then
self.dy = 0 -- hit block top
self.onBlock = true
self.onGround = false
end
if (collisions[i].normal.x ~= 0) then
self.hit_block_side = true
if self.dy > 0 then
self.dy = 0
end
self.dx = -self.dx/2
--self.dx = 0
end
end