# Zombie Conga not working as intended, missing pages?

**URL:** <https://forums.kodeco.com/t/zombie-conga-not-working-as-intended-missing-pages/19394>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [September 6, 2016, 4:28am UTC](https://forums.kodeco.com/t/zombie-conga-not-working-as-intended-missing-pages/19394 "2016-09-06T04:28:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakob123](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jakob123/32/40678_2.png) [@jakob123](https://forums.kodeco.com/u/jakob123)\
**Post date:** [September 6, 2016, 4:28am UTC](https://forums.kodeco.com/t/zombie-conga-not-working-as-intended-missing-pages/19394/1 "2016-09-06T04:28:15Z")

</div>

I’ve followed all the instructions in the book, yet when I run the app ( I’m at page 70), when I tap directly in front of the zombie, he speeds moves WAY too fast. and if I click behind him, he disappears from the view, and can’t be brought back.

I’ve downloaded the source code of the finished app, and it does look different, but nothing of this “new code” is in the pages that I’ve read so far.

How can I fix this odd behaviour of the zombie as described above, the code looks exactly like the one in the book, I have double checked.

Here’s my source code

> import SpriteKit

> class GameScene: SKScene {
> 
> ```
> let zombie = SKSpriteNode(imageNamed: "zombie1")
> var lastUpdateTime: NSTimeInterval = 0
> var dt: NSTimeInterval = 0
> let zombieMovePointPerSec: CGFloat = 480.0
> var velocity = CGPoint.zero
> let playableRect: CGRect
> 
> override init(size: CGSize) {
> let maxAspectRatio: CGFloat = 16.0 / 9.0 //1
> let playableHeight = size.width / maxAspectRatio // 3
> let playableMargin = (size.height - playableHeight) / 2.0
> playableRect = CGRect(x: 0, y: playableMargin, width: size.width, height: playableHeight)
>     
> super.init(size: size)
> }
> 
> required init(coder aDecoder: NSCoder) {
> fatalError("Init(coder:) has not been implemented")
> }
> 
> override func didMoveToView(view: SKView) {
> backgroundColor = SKColor.blackColor()
>     
> let background = SKSpriteNode(imageNamed: "background1")
> background.position = CGPoint(x: size.width, y: size.height)
> background.anchorPoint = CGPoint(x: 0.5, y: 0.5) // default
> background.zPosition = -1
> addChild(background)
>     
> let mySize = background.size
> print("Size: \(mySize)")
>     
> zombie.position = CGPoint(x: 400, y: 400)
> addChild(zombie)
> 
> ```

> ```
> }
> 
> ```

> ```
> // zombie.setScale(2.0)
> 
> override func update(currentTime: NSTimeInterval) {
> if lastUpdateTime > 0 {
> dt = currentTime - lastUpdateTime
> } else {
> dt = 0
> }
> lastUpdateTime = currentTime
> print("\(dt*1000) ms since last update")
> moveSprite(zombie, velocity: velocity)
> boundsCheckZombie()
> }
> 
> func moveSprite(sprite: SKSpriteNode, velocity: CGPoint) {
> let amountToMove = CGPoint(x: velocity.x * CGFloat(dt), y: velocity.y * CGFloat(dt))
> print("Amount to move: \(amountToMove)")
>     
> // 2
> sprite.position = CGPoint(
> x: sprite.position.x + amountToMove.x,
> y: sprite.position.y + amountToMove.y)
> }
> 
> func moveZombieToward(location: CGPoint) {
> let offset = CGPoint(x: location.x - zombie.position.x, y: location.y - zombie.position.y)
>     
> let length = sqrt(Double(offset.x * offset.y * offset.y))
>     
> let direction = CGPoint(x: offset.x / CGFloat(length), y: offset.y / CGFloat(length))
>     
> velocity = CGPoint(x: direction.x * zombieMovePointPerSec, y: direction.y * zombieMovePointPerSec)
> }
> 
> func sceneTouched(touchLocation: CGPoint) {
> moveZombieToward(touchLocation)
> }
> 
> override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
> guard let touch = touches.first else {
> return
> }
> let touchLocation = touch.locationInNode(self)
> sceneTouched(touchLocation)
> }
> 
> override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
> guard let touch = touches.first else {
> return
> }
>     
> let touchLocation = touch.locationInNode(self)
> sceneTouched(touchLocation)
> }
> 
> func boundsCheckZombie() {
> let bottomLeft = CGPointZero
> let topRight = CGPoint(x: size.width, y: size.height)
>     
> if zombie.position.x <= bottomLeft.x {
> zombie.position.x = bottomLeft.x
> velocity.x = -velocity.x
> }
>     
> if zombie.position.x >= topRight.x {
> zombie.position.x = topRight.x
> velocity.x = -velocity.x
> }
>     
> if zombie.position.y <= bottomLeft.y {
> zombie.position.y = bottomLeft.y
> velocity.y = -velocity.y
> }
>     
> if zombie.position.y >= topRight.y {
> zombie.position.y = topRight.y
> velocity.y = -velocity.y
> }
>     
>     
> }
> 
> ```

> }

---

<div class="post-metadata">

**Author:** ![narrativium](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/narrativium/32/110937_2.png) [@narrativium](https://forums.kodeco.com/u/narrativium)\
**Post date:** [September 6, 2016, 4:59pm UTC](https://forums.kodeco.com/t/zombie-conga-not-working-as-intended-missing-pages/19394/2 "2016-09-06T16:59:15Z")

</div>

It might not be the only thing, but this formula (from page 68) isn’t correct:

> [@jakob123](#):
>
> let length = sqrt(Double(offset.x \* offset.y \* offset.y))

This one should be

```auto
let length = sqrt(Double(offset.x * offset.x + offset.y * offset.y))

```

Double-check your equations, and see if anything else is different.

---

<div class="post-metadata">

**Author:** ![jakob123](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jakob123/32/40678_2.png) [@jakob123](https://forums.kodeco.com/u/jakob123)\
**Post date:** [September 6, 2016, 5:34pm UTC](https://forums.kodeco.com/t/zombie-conga-not-working-as-intended-missing-pages/19394/3 "2016-09-06T17:34:26Z")

</div>

Oh my, I’m sorry if I came across as rude, it was just this one line of code that messed it all up.

Many, many thanks.
