0
\$\begingroup\$

I want to make a 2D soccer game on iOS, I started with SpriteKit and got the ball physics working. Now, I could make the goal simple and static, but I'd love to make it make it elastic like a real one when the ball hits the net. I started creating the goal with the post, two ropes (on the top and rear side). The ropes are basically like the ones in https://github.com/DigitalBuckeye/SKSwiftRopeDemo.

My problem is, when I hit the ball fast enough against the ropes, it will pass through them (even with usesPreciseCollisionDetection enabled).

I couldn't find any 2D sample for a good goal net on the web, tried searching in the box2d and chipmunk communities.

I wonder if I'll have to use a 3D engine for that.

\$\endgroup\$
2
  • \$\begingroup\$ It's not connected with question, but it's a tip: You should add .DS_Store files to .gitignore. \$\endgroup\$ Commented Jan 13, 2016 at 14:19
  • \$\begingroup\$ Thanks Marqin, but that github repo is not mine ;-) \$\endgroup\$ Commented Jan 13, 2016 at 14:20

1 Answer 1

1
\$\begingroup\$

My problem is, when I hit the ball fast enough against the ropes, it will pass through them (even with usesPreciseCollisionDetection enabled).

This is probably because it's moving so fast that:

  • Frame n: Ball is still in front of net, not colliding with net.
  • Frame n+1: Ball is on the different side of net, not colliding with net.

This problem has it's own question, so I'll just summarize possible options:

  1. Limit ball speed.
  2. Check in every frame if ball had passed trough net.
  3. Do collision test in each frame ( before moving ball ) with some raycast to check if path in front of ball is clear ( no obstacles, eg. net ).
  4. "Create a minimal bounding box that contains [ball position in] Frame n and Frame n+1 and see if the goal intersects [with this box]" - as suggested in comment by Erno de Weerd
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Or create a minimal bounding box that contains Frame n and Frame n+1 and see if the goal intersects \$\endgroup\$ Commented Jan 13, 2016 at 14:39
  • \$\begingroup\$ That suggestion may be a broad phase check. A bounding box can be created where the ball in frame n is near the edge of the net, n+1 behind and left of the net. The bounding box will intersect, however the path of the ball just missed the goal in reality. \$\endgroup\$ Commented Jan 13, 2016 at 14:58
  • \$\begingroup\$ ^ Only when ball can move on a curve. \$\endgroup\$ Commented Jan 13, 2016 at 15:01
  • \$\begingroup\$ Well if you make the boundingbox rotate you're correct that it will always intersect. However in a 2D game boundingboxes are usually axis aligned. In that event you can draw a box that intersects without the path actually hitting the goal. If you are going to rotate the boundingbox you are better off doing a line intersection of the ball path with the goal rope, which is the easiest solution to the OP's question. You get the intersectionpoint as a result to keep the ball inside the goal and have the net react to the impact at the correct spot. \$\endgroup\$ Commented Jan 13, 2016 at 17:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.