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?
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).
Related
Im building a game where the node will move either up down left or right on the screen.
To do this im applying a velocity in whichever direction the person swipes. The issue here is that as the node moves along it's speed gradually reduces.
The main thing im trying to do is to have the node move at a constant speed in whichever direction its currently moving. is there a way i can stop the velocity from decreasing over time or possibly another way of moving the node at a constant speed?
You need to set the physics body's linearDamping to 0.
The linear damping is meant to simulate friction, and reduces the velocity of a physics body over time. The default value is 0.1.
I have two balls of equal mass that hit each other straight on. I can't seem to figure out why there is a rebound effect on the incoming ball. I am using sprite kit.
I thought it was the restitution property. I have it set to 1 (which is what I thought it should be), but have tried many.
The only way I can kill the rebound is to change the mass, which messes up other things.
If the speed is slow it pretty much stops as it should. But at higher speeds there is a bounce back. They should just exchange velocity as it is a head on collision. Is it possibly some numerical rounding at high speeds or something?
http://h2physics.org/?cat=4
actually restitution 0 should disable any bouncing effect, 1 means the body leaves the surface with the same velocity it impacted with
Ok, I'm making a physics game with Corona SDK. To fire a ball, you pull back and release, the linear impulse is based on that distance. The ball is a sprite with 2 frames, so you can change the color of the ball. When I change the frame of the ball, which is in a different "settings" scene, and go back to the "level1" scene, the ball hits and bounces off 'invisible' objects. Also, the linear impulse applied is much greater than it should be. If I change the frame back it doesn't fix anything. Any thoughts on what this could be? Thanks!
this is what i'm trying to do, 2 balls will drop at different height, their bounce is set to 1.0, which means after bounce they will go back to their original position. But the higher ball will drop and bounce faster than the lower ball, so when the higher ball bounces and goes back to it's original position once, the lower ball finishes its first bounce too.
is ok that they don't bounce once at the same time? i just want to know how i can change their speed.
so far what i have found is that we can't change their mass, density won't effect drop speed, set gravity will effect both. any solution please?
and i'm trying to change the mass of those ball, so the ball that higher from the ground can drop faster
Heavier things do not fall faster. Either in reality or a proper simulation thereof. The reason why we think of heavy things falling faster is because of air resistance. Objects moving through the air have resistance from that air, and this slows down light objects more than heavier ones.
So you would either have to break the physics system or implement air resistance.
I'm implementing a small game and am having trouble getting the physics working properly.
In this game, there is one ball (a circle which moves from frame to frame, and may change radius) and several walls (line segments which also change and move from frame to frame). I can detect collisions properly, and making the ball bounce off in the correct direction is no problem.
Difficulties arise in situations where the ball intersects a line in one frame, then intersects it again in the subsequent frame, causing a double bounce. I could move the ball back along the normal of the line until it is in a valid position, but this causes really weird behaviour when the line in question is being hit along its axis (imagine a ping pong ball falling down on an upright toothpick and suddenly shifting aside so that it is on one side of the toothpick...). There are also a few issues when the ball intersects more than one line in a given frame (imagine four lines together making a rectangle and the ball intersecting the corner of said rectangle) -- which direction should it bounce off? In which direction should it shift?
I don't really have a specific question, but am looking for tips or some useful tutorials. All the 2D ones I've managed to find so far only cover rectangle intersections.
I'm using XNA if it makes any difference.
Thanks,
Cameron
This is an universal problem with most physics libraries. If you google for "penetration depth" (together with "physics", I suggest, or you might find something entirely different :D) you will find that even these libraries use tricks like yours.
There are two solutions to this:
The cheap one is to increase your update frequency. Move objects in 10 smaller steps instead of a single big one and you will have less penetration, so fixing it by offsetting the ball away from the wall will be less visible.
The expensive one is continuous collision detection. There are algorithms that can tell you, given a moving and a stationary object, the exact point in time both will will intersect. Google "swept sphere rectangle intersection" to find some of these.
You can then update like this: ball needs to move by 1.0 units. Check for collision. Collision occurs after 0.25 units, so move ball by 0.25 units, calculate reflection vector (so the ball bounces off the wall), repeat collision check with remaining 0.75 units (until you know the final position of the ball). This avoids penetrations entirely and even if your ball is moving so fast that it would normally skip over the wall in a single update, the collision will be detected.
It's generally accepted that, because of the timestep your collisions will intersect past an acceptable point in between updates.
Basically, you have to interpolate back to the point in between the last and current frame where the collision truly happened, move the object back to that point, and then calculate the forces, etc.