improvement: port goTo3D to motion

This commit is contained in:
Kazhnuz 2021-08-07 10:36:44 +02:00
parent ee1995b91b
commit 80d18a2825

View file

@ -91,17 +91,13 @@ function Movable:goTo(dx, dy, duration, easing)
end end
function Movable:goTo3D(dx, dy, dz, duration, easing) function Movable:goTo3D(dx, dy, dz, duration, easing)
local easing = easing or 'inOutQuad'
self:stopMoving() self:stopMoving()
self:stopJumping() self:stopJumping()
self.jump.useDefaultAnimation = false self:setTarget(dx, dy, dz)
if duration > 0 then local speed = utils.math.pointDistance3D(self.x, self.y, self.z, dx, dy, dz) / duration
self.tweens:setNamedTween("goTo", 0, duration, {x = dx, y = dy, z = dz}, easing) self:setMotionToPoint(speed, dx, dy, dz)
end
self.tweens:newTimer(duration + 0.02, "goTo")
self.tweens:newTimer(duration + 0.02, "resetMovement")
self.movementType = MOVEMENT_TWEENER self.movementType = MOVEMENT_TARGET
end end
function Movable:updateTweenerSpeed(dt) function Movable:updateTweenerSpeed(dt)
@ -111,14 +107,24 @@ end
-- MOTION HANDLING -- MOTION HANDLING
function Movable:setMotion(speed, angle) function Movable:setMotion(speed, angle, vertAngle)
self.speed = speed self.speed = speed
self.angle = angle self.angle = angle
self.motion3D = (vertAngle ~= nil)
if (self.motion3D) then
self.vertAngle = vertAngle
end
self.movementType = MOVEMENT_MOTION self.movementType = MOVEMENT_MOTION
end end
function Movable:setMotionToPoint(speed, dx, dy) function Movable:setMotionToPoint(speed, dx, dy, dz)
self:setMotion(speed, utils.math.pointDirection(self.x, self.y, dx, dy)) 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 end
function Movable:updateMotion(dt) function Movable:updateMotion(dt)