simple bouncing ?

Aug 17, 2008 at 8:44 PM
hi dear admins and friends,

i study farseer physics for a while and i am a beginner and for the first time writting here.

my problem is :

i try to make a simple code about a bouncing object with gravitation.(just the same you release a ball from your hand and watch its motion on the road)

-ball is falling horizontally.
-when it collide at a certain screen point (i.e Y=800) it bounces up with a force.
-i need to make its bounce slow and then stop.
-then i used "ball.lineardragcoefficient = 1"
-it slowed but at the point Y=800 it always jump.

can you help me

regards

myriac





Coordinator
Aug 18, 2008 at 5:46 PM
"-ball is falling horizontally.
-when it collide at a certain screen point (i.e Y=800) it bounces up with a force.
-i need to make its bounce slow and then stop.
-then i used "ball.lineardragcoefficient = 1"
-it slowed but at the point Y=800 it always jump."

Is that your current progress? So now your current problem is that it always jump at y=800 it jumps?
Could you provide a demo or screenshot to make it easier to help you.

My first idea was just to deactivate the object that makes it bounce up again, once it already has bounced, but this might not be the solution as I do not understand the problem fully.
Aug 18, 2008 at 6:46 PM
firstly , thank you genbox for your reply

it is a very simple thing i know..think that you have just one ball on the screen.

program has a gravitation so it falls
            physicsSimulator = new PhysicsSimulator(new Vector2(0,200));


when ball reach i.e Y=800 i want it to jump up until it stops like in real life genbox.. think you hold a tennis ball in your hand , and then you throw it onto the ground , it falls on the ground and then jumps a few times and then stops because of gravitation.

if (ball.Position.Y >= 800)
            {              
               ball.ApplyForce(new Vector2(0,-500);
            }
          
above is in the update part of the code.

it jumps up ok but every time it reaches Y=800 it always jump. how will i cease its velocity, LIKE IN REAL LIFE..

Coordinator
Aug 19, 2008 at 12:05 AM
Oh, okay.

So what you say is that you want it to gradually loose it's altitude instead of bouncing up to 800px again?
If that's the case, take a look at this thread:

Supress bouncing

You should also take a look at some of the properites and try tweaking them to get it to behave. Using physics in a game means a lot of physics tweaking :)

Oh by the way: Could could also counteract the force by applying another force to the ball. This however should now be necessary and would be considered a hack in the world of physics. ;)
Aug 19, 2008 at 3:11 PM
Looks like you are applying a force every time the ball is higher than 800, correct? My guess is that by applying this force on each bounce, you are maintaining the momentum of the ball. You are applying the same downward force on the ball for each bounce above 800, thus ensuring that on the next bounce will be the same height as the previous one. If the downward force you are applying is large enough to send the ball above 800 this will act like an infinite loop, with the ball always going above 800, receiving the downward force, and going back above 800. If you decrease the downward force to an amount that will not send the ball above your limit, and then gradually decrease this force over time your approach may work.

I would abandon the approach of mimicking gravity with downward forces, and do as genbox says. Try tweaking the linear drag coefficients for the ball (increasing the drag should slow down the ball) or increasing the force of gravity downward. You could also try and give your ball a larger mass. A lot of this is hit-and-miss guess work. Good luck!
Aug 19, 2008 at 3:31 PM
thank you wmfwlr

and as far as i understand there is no short way to describe at a certain point for suppressing bounce.
so i will try drag for bodies and other tweaks..

regards

myriac
Aug 19, 2008 at 5:38 PM
The best thing probably would be to use the engine's RestitutionCoefficient and LinearDragCoeffecient, but if you simply must handle the bouncing yourself, (maybe you have no body to bounce off of or want to control the power of the bounce) try the line of code below.  This is taken from the snippit you posted above.

ball.ApplyForce(new Vector2(0f, ball.Velocity.Y * -1.9f);

Change that value at the end to anything between -1 and -2.  -1 will halt the ball as soon as it hits that point.  -2 will make it bounce up just as high.  Anything larger then -2 will make it bounce higher each time, and anything smaller than -1 will probably make it freak out and implode all over you.  Remember that it will always be bouncing, even if it looks like it's sitting still.  If left alone for long enough, it may possibly drift below that line very slowly due to rounding errors. (Don't take my word for it.  I don't know much about that.)
Aug 19, 2008 at 6:35 PM
thanx a lot yota, but it's still bouncing as you mentioned.

i think it's because of wheter applyforce method in the if statement  or because of the screen coordinate comparison Y>=800..

maybe i need to use a plane on the bottom of the screen will collide with my ball huh ? but believe me i didnt want to use another object, coz i thought that it must bounce when it passes Y>=800 and then stops
but cant do it, i am very frustrated..


:((

Aug 20, 2008 at 5:24 PM
If you want it to simply stick to the bottom of the screen once the bouncing slows down, you could try replacing the line I mentioned with:

ball.ApplyForce(new Vector2(0f, ball.Velocity.Y * (ball.Velocity.Y < 5f ? -1f : -1.9f));

Just tweak the '5f' to adjust how easily it snaps to the edge.  It is still possible that, even when the ball stops, it may be slightly off the edge of the screen.  Just check the position and bump it up to where it should be, I suppose. (A physics expert, I am not.)

Let me know if I'm misinterpreting your problem, also.
Aug 22, 2008 at 12:10 AM
ok Yota, you understand my problem indeed.

i tweak value 5f according to my code.
this works good, bu let me say that something goes not well ..

everytime i ran program : sometimes ball stick to the gorund for the first time , and sometimes it bounce a few times (this is good one ) and then stops.
it's not stable for  every running ..
???

btw, my gravitation value 200 (if any help ?).

thanks for your help,

i wait for your reply

regards,

myriac