From 80d18a28256be906aa0da6c8a32374a5cc587358 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 7 Aug 2021 10:36:44 +0200 Subject: [PATCH] improvement: port goTo3D to motion --- .../scenes/battlesystem/actors/movable.lua | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua index 48a1cd7..00d22be 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/movable.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/movable.lua @@ -91,17 +91,13 @@ function Movable:goTo(dx, dy, duration, easing) end function Movable:goTo3D(dx, dy, dz, duration, easing) - local easing = easing or 'inOutQuad' self:stopMoving() self:stopJumping() - self.jump.useDefaultAnimation = false - if duration > 0 then - self.tweens:setNamedTween("goTo", 0, duration, {x = dx, y = dy, z = dz}, easing) - end - self.tweens:newTimer(duration + 0.02, "goTo") - self.tweens:newTimer(duration + 0.02, "resetMovement") + self:setTarget(dx, dy, dz) + local speed = utils.math.pointDistance3D(self.x, self.y, self.z, dx, dy, dz) / duration + self:setMotionToPoint(speed, dx, dy, dz) - self.movementType = MOVEMENT_TWEENER + self.movementType = MOVEMENT_TARGET end function Movable:updateTweenerSpeed(dt) @@ -111,14 +107,24 @@ end -- MOTION HANDLING -function Movable:setMotion(speed, angle) +function Movable:setMotion(speed, angle, vertAngle) self.speed = speed self.angle = angle + self.motion3D = (vertAngle ~= nil) + if (self.motion3D) then + self.vertAngle = vertAngle + end self.movementType = MOVEMENT_MOTION end -function Movable:setMotionToPoint(speed, dx, dy) - self:setMotion(speed, utils.math.pointDirection(self.x, self.y, dx, dy)) +function Movable:setMotionToPoint(speed, dx, dy, dz) + local angle = utils.math.pointDirection(self.x, self.y, dx, dy) + local vertAngle = nil + if (dz ~= nil) then + local distance2D = utils.math.pointDistance(self.x, self.y, dx, dy) + vertAngle = utils.math.pointDirection(0, self.z, distance2D, dz) + end + self:setMotion(speed, angle, vertAngle) end function Movable:updateMotion(dt)