As of now the player moves with the platform but if i want to move around the moving plaftorm i have some glitchy behaviour, which is even more evident when the platform speed is almost = player speed;
here some relevant code (all of this is inside player:update() by the way):
(I tried coming up with two things but one made that slow /glitchy behaviour; the other one shoved the player away from the platform)
Code: Select all
-- HOW IT MOVES:
if isDown("left") then
self.dir = -1 --self.direction
self.dx = self.dir * self.spd
elseif isDown("right") then
self.dir = 1
self.dx = self.dir * self.spd
end
if love.keyboard.wasPressed("z") and self.on_ground then
self.dy = self.jumpspd
self.on_ground = false
self.otherdx = 0
end
self.on_ground = false
self.dx = math.abs(self.dx) < 10 and 0 or self.dx - self.dir * self.friction
self.dy = self.dy > self.maxvspd and self.maxvspd or self.dy + self.gravity
-- WHAT I TRIED:
--A local fakespd = self.dx * self.otherdx ~= 0 and self.dx -sign(self.dx) * self.otherdx or self.dx
--B self.dx = self.dx * self.otherdx < 0 and self.dx -sign(self.dx) * self.otherdx or self.dx
--------------
local goal_x = self.x + (self.dx + self.otherdx) * dt
local goal_y = self.y + self.dy * dt
local cols
self.x, self.y, cols = self.world:move(self, goal_x, goal_y, self.filter)
-- COLLISION RESOLUTION
if not g_WAIT then
for i, c in ipairs (cols) do
-- walls are the only things without id
if not c.other.id then
if c.normal.y == -1 then
self.dy = 0
if self.current_animation == "fall" then self.current_animation = "ground" end
self.on_ground = true
elseif c.normal.y == 1 and not c.other.id then
self.dy = -self.dy/4
end
if c.normal.x ~= 0 and not c.other.id then
self.dx = 0
end
elseif c.other.id == "box" then
if c.normal.y == -1 then
self.dy = 0
self.otherdx = c.other.otherdx
-- the box itself is on top of an enemy and is such that was box.otherdx = enemy.dx
if self.current_animation == "fall" then self.current_animation = "ground" end
self.on_ground = true
end
if c.normal.x ~= 0 and self.on_ground then
c.other.dx = math.floor(self.dx / 2)
end
elseif c.other.id == "enemy" then
self:death()
end
end
end
end