I'm working on a jumper iOS game where the 'player' moves on a wave. It should be able to jump and land on the wave. In the current version it jumps but doesn't move back down.
It does work when the platform is not moving, but the moving platform is crucial for the app.
Thanks, guys!
Code
The platform 'characterBaseline' is moving based on this function
wave.bar.position.y = CGFloat(Double(wave.bar.position.y) + createSinWave(angle))
func createSinWave(angle:Double) -> Double {
var sinWave = sin(angle)
return sinWave
}
The player's jump and moves are based on the following function
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if self.onGround {
self.velocityY = -14.0
self.onGround = false
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if self.velocityY < -7.0 {
self.velocityY = -7.0
}
}
override func update(currentTime: NSTimeInterval) {
// Character op wave
self.character.position.y = CGFloat(Double(self.character.position.y) + createSinWave(angle))
self.characterBaseline = self.character.position.y
// Jump
self.velocityY += self.gravity
self.character.position.y -= velocityY
if self.character.position.y < self.characterBaseline {
self.character.position.y = self.characterBaseline
velocityY = 0.0
self.onGround = true
}
// Golf
updateWaveBarPosition()
}