improvement: port goTo3D to motion
This commit is contained in:
parent
ee1995b91b
commit
80d18a2825
1 changed files with 17 additions and 11 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue