March 11th, 2009

Silverlight gravity simulation on a dragable ball

All Silverlight Examples, Silverlight 2 tutorials, Silverlight C# Tutorials, Silverlight Effects, Silverllight Games, by Gavin Wignall.

So below is a first attempt on implementing gravity on a dragable object. There are a couple minor bugs still but the core idea generally works.

Use the mouse to click and drag the ball, move the mouse and let go of the mouse button as you’re moving the mouse. The ball will pick up on the direction you were moving and continue in the same direction.


While the ball continues in this direction a force will pull the ball towards the ground, effectively trying to simulate gravity.

If the ball hits the ground the momentum built up by the ball will be reflected partially and rebound the ball back upwards.

If the ball hits the left, top or right boundary then the ball will be reflected partially and rebound in the opposite direction.

If the ball is dragged outside the of the boundaries of the Silverlight area then the ball will continue to move in the direction it was going in at the last point of contact, bouncing off the related boundary.

I have featured 2 Sliders to allow you to adjust the variables slightly to change the effect on the ball.

Future Enhancements

There are still a few bugs, every so often the ball will react a bit crazy – this is due to my coding no doubt, I would like to address this.

I would like to implement a dragable block that the ball would react and bounce off.

I would like to be able to have multiple balls on the stage with different properties that can additionally interact/bounce off each other

Get the code

As always you can grab the code here, please pull it apart and enjoy!

Back Top

Responses to “Silverlight gravity simulation on a dragable ball”

  1. Interesting blog, nice design, i have bookmarked it for the future referrence

  2. Interesting website, i have bookmarked your site for future referrence :)

    teksty z linkiem at June 26, 2009 4:07 pm
  1. No trackbacks yet.

Leave a Reply

Back Top