0

If I had a SKSpriteNode on the screen, how would I be able to flick it so that it would simulate the physics of a soccer ball being kicked. how to throw SKSpriteNode? I am guessing that it would be sort of like this question, but instead of the node following your finger first before it is flicked shouldn't happen. It should look like when you flick you are swiping towards the node and then once your finger hits the node it moves it like the physics of a soccer ball. Can anyone give me a place to start in order to achieve this??

Community
  • 1
  • 1
PoKoBros
  • 701
  • 3
  • 9
  • 25
  • http://www.techotopia.com/index.php/An_iOS_7_Sprite_Kit_Collision_Handling_Tutorial – Adrian Oct 07 '15 at 01:56
  • @AdrianB does this show how to flick an SKSpriteNode?? I don't see it... – PoKoBros Oct 07 '15 at 02:00
  • My apologies. It sounded like you were starting off at ground zero and were looking for a place to start. I've found techtopia tutorials very helpful. Gesture recognizers as they relate to SKSpriteNodes are discussed here. http://www.raywenderlich.com/44270/sprite-kit-tutorial-how-to-drag-and-drop-sprites – Adrian Oct 07 '15 at 02:08

1 Answers1

1

I would recommend using the touchesBegan method and touchesMoved method. Basically, keep track of the last position of the touch, along with the timestamp (using NSTimeInterval), and on each touchesMoved check if the soccer ball has the touch location inside it (using [soccerBall containsPoint:location]. Then, calculate the force that you should impart on the ball (compare timestamps, and compare positions), and then run:

[soccerBall.physicsBody applyImpulse:CGVectorMake(dx, dy)];

Replace dx and dy with the results of your calculations. You may wish to add a scale value to make sure that you get the results you are looking for.

Gliderman
  • 1,195
  • 9
  • 18