JohnSundell / JohnSundell/ImagineEngine

Player jumping to top-left in Walkabout tutorial

Open
#172 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Swift
Stars
1.8k
Forks
104
PR merge metrics
No merged PRs in 30d

Description

Hi!

I just tried gave ImagineEngine a try and followed the Walkabout tutorial. Somehow I'm seeing weird behavior, when I click on a horizontal axis right of the player (see attached gif). Sometimes, the player just jumps to the top-left corner of the scene.

To be sure that this isn't a bug caused by me, I copied the content of `FinalCode.swift` and it still happens.

Afterwards I modified the code to print some stuff:
```diff
events.clicked.observe { _, point in
+ print("click: \(point)")
moveToken?.cancel()

let speed: Metric = 100
let horizontalTarget = Point(x: point.x, y: player.position.y)
let horizontalDuration = TimeInterval(abs(player.position.x - point.x) / speed)
let verticalTarget = Point(x: point.x, y: point.y)
let verticalDuration = TimeInterval(abs(player.position.y - point.y) / speed)

moveToken = player.move(to: horizontalTarget, duration: horizontalDuration)
.then(player.move(to: verticalTarget, duration: verticalDuration))
.then(player.playAnimation(idleAnimation))
+ .then { print("horizontalTarget: \(horizontalTarget), verticalTarget: \(verticalTarget), player.position: \(player.position)") }
}
```

This are the print statements when the bug occured:
```
click: (268.0, 309.0)
horizontalTarget: (268.0, 384.0), verticalTarget: (268.0, 309.0), player.position: (268.0, 309.0)
click: (387.0, 309.5)
horizontalTarget: (387.0, 309.0), verticalTarget: (387.0, 309.5), player.position: (387.0, 309.5)
click: (506.0, 309.5)
horizontalTarget: (506.0, 309.5), verticalTarget: (506.0, 309.5), player.position: (16.0, 23.0)
```

Somehow the position of the player is `(16.0, 23.0)` when it should be `(506.0, 309.5)` 🤔
Its quite easy to reproduce by clicking top-left of the player and then twice on the right side of the player as in the gif and seen in the logs.

![player_jumping_top_left](https://user-images.githubusercontent.com/7734806/37916919-5c527cf6-311d-11e8-9b5b-73f151ff398f.gif)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.