5

I have an infinitely bouncing ball simulation that works properly. The ball bounces around the screen borders forever.

One minor problem though is that if the starting impulse is too small the ball never bounces to begin with.

I experimented and eventually found that a starting impulse of at least 2.1 for my ball is required for it to bounce.

ball.physicsBody!.applyImpulse(CGVectorMake(-2.1, -2.1))

If I set the value to 2 the ball never starts bouncing it just stops at the bottom left corner.

ball.physicsBody!.applyImpulse(CGVectorMake(-2.0, -2.0)) //ball stops

I actually came across a question that answered this, but I forgot how to get to it. I know there is some lower limit that spritekit enforces to make a moving object stop when a collision occurs.

If I could get to that answer that would be great. Also if there is a way to override that, and make an object still bounce with a slower starting impulse that would be great too thanks.

edit: so I re-found the other question, SpriteKit ball loses all energy hitting wall, restitution=1

so my new question is, is there a way to set or lower the velocity threshold in sprite kit? I would like my ball to be able to move slower.

edit: anyone?

Community
  • 1
  • 1
shwick
  • 4,277
  • 6
  • 21
  • 28
  • 1
    You need to be more specific. What exactly do you mean by making your ball move slower? Do you want to apply linear damping? Do you want to set the ball's velocity as a constant vector? – Andriko13 Oct 26 '14 at 01:48
  • I want the ball to continue to have elastic collisions while the velocity is below b2_velocityThreshold. Hence I need to set this limit somehow. It is explained better in the question I linked. – shwick Oct 26 '14 at 04:45
  • I see what you're saying. The only solution I see right now is to do so with some custom physics (as regular physics don't satisfy your needs d:). What I would do is check when collision/contact occurs and reverse the velocity of the ball. For example, if the ball hits the upper or lower bound, apply a y-impulse that is negative of your original, same for hitting the horizontal bounds and an x-impulse. – Andriko13 Oct 26 '14 at 17:08
  • Thanks I will consider that as an option. This seems like something that would frequently happen, people wanting slow moving objects. Dunno why its not easier to set. – shwick Oct 26 '14 at 17:55
  • I haven't yet needed to ever make anything bounce that slowly, for what purpose do you need it? – Andriko13 Oct 26 '14 at 17:56
  • I was just thinking I would vary the top speed of my pong balls based on latency to smooth gameplay. Poor connections would cause slower ball speed so the game would still be playable. Perhaps so slow that it would stop the collision. – shwick Oct 26 '14 at 18:06
  • If your app will use an internet connection, having minimum connection strength must be an assumption. I don't think having the balls move that much slower makes the game more playable. It really is up to you, however. Good luck, and if you find a solution post it! – Andriko13 Oct 26 '14 at 18:21

1 Answers1

0

Your ball has a weight to it.

It's like in the real world - if you try push a chair with little force, it won't move as it has a weight.

However, if you push harder, the chair will start to move, but it does not start from 0.1 N of force (it really depends on the weight, friction and a few other factors).

George
  • 25,988
  • 10
  • 79
  • 133