Abdul Ahmad
Abdul Ahmad

Reputation: 10021

calculating angle based on user touch

I have a game with a character that can cast fire balls. Right now in my game, when I tap anywhere on the screen, I shoot a fireball at my touch point. For this fireball I'm using an SKEmitterNode where I've created a fireball particle emitter.

The problem I'm running into is, my fireball has an angle set already, but I want that angle to change based on where I tap, so that the trailing flames are behind the fireball, not going up or down or whatever I've set it to in the sks file.

I've never done something like this, is there something built into swift already for calculating angles? I can't find much on google

Upvotes: 0

Views: 409

Answers (1)

wm.p1us
wm.p1us

Reputation: 2059

There are two options:

1) first one is that you can use :

fireBall.moveTo(touchLocation.x, touchLocation.y)

function so you can avoid use angles (if I understand you correctly). touchLocation is CGPoint of location of the touch event.

2) second one use as it was said before you will get an angle:

atan2(deltaY,deltaX)

Upvotes: 1

Related Questions