# Trigonometry for Game Programming – SpriteKit and Swift Tutorial: Part 1/2

Learn trigonometry for game programming using SpriteKit and Swift. You will learn the theory and then practice using trigonometry by making a space shooter game!

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5504-trigonometry-for-game-programming-spritekit-and-swift-tutorial-part-1-2
1 Like

Great job with this tutorial, particularly the rotation blending, which is awesome - I have one issue; in my game, I lock the screen orientation, so if the player tilts too far forward, the screen doesn’t flip on them - however, if I tilt too far forward, my player sprite reverses direction, and moves toward me instead of away from me. If I relax the tilt, the sprite will reverse again, and correctly move away from me. Tilting back does not do this regardless of the degree I may tilt the device. I’m assuming there’s a way to control forward tilting so this does not happen, but I can’t put my finger on it? Thanks for any guidance.

False alarm! The problem turned out to be far simpler than I thought, and completely unrelated to this topic: I wasn’t handling the change in screen orientation properly; once I changed what I was doing to the following, it worked like a charm:

if UIApplication.shared.statusBarOrientation == .landscapeRight {
accX = accelerometerData.acceleration.x
accY = accelerometerData.acceleration.y * -1
} else {
accX = accelerometerData.acceleration.x * -1
accY = accelerometerData.acceleration.y
}

@balke Thank you for sharing the solution - much appreciated!

Hi the tutorial is very good and I am really enjoying it. I am not able to implement the blending of the old angle with the new one for the turret, which will in turn make the turret a little bit slower than the player’s ship. Thanks for any guidance.

@bmorefield Can you please help with this when you get a chance? Thank you - much appreciated! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!