Skip to content

Commit fc4a2fe

Browse files
committed
Fix PointerControlledForceComponent
PointerEventComponent.lastEvent was always the latest event, so we couldn't compare any change in movement between updates! Resolved by using PointerEventComponent.secondLastEvent
1 parent d6a8094 commit fc4a2fe

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/OctopusKit/Components/Input/Pointer/PointerControlledForceComponent.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// CHECKED: This component works whether the `PointerEventComponent` is added to a sprite entity or the scene entity. :)
1212

13-
// TODO: Fix physics and grabbing behavior etc.
13+
// TODO: Improve physics and grabbing behavior etc.
1414

1515
import SpriteKit
1616
import GameplayKit
@@ -57,20 +57,22 @@ public final class PointerControlledForceComponent: OctopusComponent, OctopusUpd
5757
// Move the node if the pointer we're tracking has moved.
5858

5959
if self.pointing,
60-
let currentEvent = pointerEventComponent.pointerMoved,
61-
let lastEvent = pointerEventComponent.lastEvent
60+
let currentEvent = pointerEventComponent.pointerMoved,
61+
let previousEvent = pointerEventComponent.secondLastEvent,
62+
previousEvent.category != .ended
6263
{
6364
let currentPointerLocation = currentEvent.location(in: parent)
64-
let previousPointerLocation = lastEvent.location(in: parent)
65+
let previousPointerLocation = previousEvent.location(in: parent)
6566
let vector = CGVector(dx: (currentPointerLocation.x - previousPointerLocation.x) * boost,
6667
dy: (currentPointerLocation.y - previousPointerLocation.y) * boost)
6768
physicsBody.applyForce(vector)
69+
6870
}
69-
71+
7072
// Stop tracking a pointer if the player cancelled it.
7173

7274
if self.pointing,
73-
pointerEventComponent.pointerEnded != nil
75+
pointerEventComponent.pointerEnded != nil // CHECK: Should we use `PointerEventComponent.lastEvent`?
7476
{
7577
self.pointing = false
7678
}

0 commit comments

Comments
 (0)