0

I need to get my sphere to bounce the same distance and at the same velocity each time it collides with a box. As of right now, the ball will collide with the first box and a force is applied to make it reach the next box. Over time, the ball bounces a lesser distance towards the next box until it doesn't reach it anymore. How do I make it so that the ball will bounce on the first box towards the second box, and then once it hits the second box, travel the exact same distance it did from the first to the second? SceneKit, Swift

Tiptech
  • 177
  • 1
  • 17

1 Answers1

0

Two ways, I can think of:

Inflated, artificial resitution value:

You could mess about with the restitution (trial and error) until you find a value that sort of works, most of the time. This will need to be more than 1.0, but not much more. And it will be unreliable. Any interruptions in frame rate or other system lags will ruin it. Possible, but foible full.

or...

Artificially induce the right force amount:

Zero the balls's velocity (make it stationary) at one of the boxes, where it would be when it normally touches. Then find the exact amount of impulse to create a "bounce". Once you know that, when the ball collides with the other box, zero its velocity, and apply the opposite force. When it reaches the first box, zero velocity again, and apply that first found force... over and over again. Looks like bouncing, works perfectly every time, but is fake bouncing.

Warning: Due to the unreliable nature of SpriteKit and SceneKit physics (not delta-d), you may even want to reposition your ball to its ideal point of start each time, too. Just in case some drift occurs.

Confused
  • 6,048
  • 6
  • 34
  • 75
  • Thank you for your answer. Is unity more reliable than SceneKit for my type of problem? – Tiptech Oct 03 '16 at 18:10
  • No. Nothing is more unreliable than Unity. @TiptonixBeats – Confused Oct 04 '16 at 04:45
  • By which I mean to say Unity is the benchmark in unreliability, and that this is the only thing they've ever been consistent in or about. For which we should probably applaud them, I suppose @TiptonixBeats – Confused Oct 04 '16 at 04:46