Improved moving
This commit is contained in:
parent
d80733a597
commit
522b4958b5
@ -56,12 +56,15 @@ const updatePosition = (x: number, y: number) => {
|
|||||||
tween.value.stop()
|
tween.value.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const distance = Math.sqrt(Math.pow(targetX - currentX.value, 2) + Math.pow(targetY - currentY.value, 2))
|
||||||
|
const duration = distance * 5 // Adjust this multiplier to control overall speed
|
||||||
|
|
||||||
tween.value = props.layer.scene.tweens.add({
|
tween.value = props.layer.scene.tweens.add({
|
||||||
targets: { x: currentX.value, y: currentY.value },
|
targets: { x: currentX.value, y: currentY.value },
|
||||||
x: targetX,
|
x: targetX,
|
||||||
y: targetY,
|
y: targetY,
|
||||||
duration: 160,
|
duration: duration,
|
||||||
ease: 'Power1',
|
ease: 'Linear',
|
||||||
onUpdate: (tween) => {
|
onUpdate: (tween) => {
|
||||||
currentX.value = tween.targets[0].x ?? 0
|
currentX.value = tween.targets[0].x ?? 0
|
||||||
currentY.value = tween.targets[0].y ?? 0
|
currentY.value = tween.targets[0].y ?? 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user