corona physics - different mass object? - lua

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.

Related

SKPhysicsBody ball won't bounce if impulse is too small

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).

Accelerate an SKSpriteNode

Is it possible to accelerate an SKSpriteNode?
I know the velocity can be set easily with node.physicsBody.velocity but how hard would it be to set it's acceleration?
Working backwards from newtons second law a motion : F = m.a
You can achieve a desired acceleration by using applyForce where the force is the acceleration multiplied by the mass.
[node.physicsBody applyForce:CGVectorMake(node.mass*acceleration.dx,
node.mass*acceleration.dy)];
applyImpulse instantly imparts a quantity of energy (in Newton.seconds). Your object doesn't accelerate so much as instantly reach the desired speed. This is unlikely to look very natural as it implies near-infinite power (energy divided by time) therefore is only really suitable for explosions (shooting bullets for example).
applyForce applies a force (in Newtons) for the time-interval the simulation runs in (i.e.: 1/60th of a second). This allows you to correctly accelerate an object and simulate many different forces being applied simultaneously (gravity, wind, rocket boost etc.) in different directions.
Also worthy of note is applyForce:atPoint: this allows you to specify at which point of the object the force is applied. For example if you were simulating a balloon with a string, the string would apply its weight to the bottom of the balloon, whereas the lift of the base in balloon would be applied to the centre of the ballon. Applying a force elsewhere than at the centre of gravity will cause the object to rotate.
Lastly, you have the corresponding applyAngularImpulse: and applyTorque: which allow you to influence an object's rotation speed. This is useful for example if you want to keep an object upright despite various bounces: you could apply a torque proportional to the angle (or square it if you want to avoid oscillations).
All this is very well documented here: SKPhysicsBody
But if you need more information about the physics themselves then have a look at Wikipedia:
Newtonian Physics and associated pages (angular momentum for example).
If you want it to accelerate, then you should change the direction of gravity for the object
self.physicsWorld.gravity = CGVectorMake(dx,dy)
but this would make everything accelerate, if that is okay

perfectly elastic collisions in sprite kit

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

Corona - Physics sliding on a surface (top down view)

How do you simulate sliding, image a circle on screen and its sliding across the screen background. Or a puck sliding in an air hockey game.
This app shows exactly what I want if you care to see an example in action!
https://itunes.apple.com/gb/app/puck-puck/id463455207?mt=8
The app is free and put it there in case someone wanted to download it to exactly see what I was talking about. My current method is using physics.start() and setLinearVelocity(200, -300), then when the object is returning "falling" down screen i physics.pause() this gives appearance of fast - gradual stop. Wondering if another way so I could use friction to change things up.
Sliding friction is a force with a constant magnitude and a direction opposite to the direction of motion.
The magnitude is a free variable you can adjust to get the motion you like. In real life it's proportional to the normal force (the force perpendicular to the surface, related to the weight) and a coefficient of kinetic friction (which is a measure of how "frictiony" the interface is -- ice or sandpaper).
Kinetic friction stops when the motion stops. Then static friction takes over, which is similir to kinetic but a little stronger, and applies as long as the object stands still. A common mistake is to botch this transition, so that the object winds up oscillating at low speed.

Collision Handling Between Circle and Line Segments

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.

Resources