This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

Builderboy2005
Builderboy2005 presents ...

2009/9/28

Rigid Body Physics

Ever since my soft-body dynamics system I have been working on a rigid-body dynamics system. That is, objects that are solid and don't move like jello :). For a while i was working with static images and trying to program in all the vector math and such, but then I came up with a more elegant solution. This simulation uses much of the same code as the soft-body simulator, with a few changed parameters to make it solid like :)

Gravity is automatic, press up to suspend.
Press left and right for left and right forces

Press 1 to go to Box mode. Click on the bokes to drag them with a ruber band.
Press 2 to go to Drag mode. Click and drag the boxes. Don't crush them!
Press 3 to go to Dice mode. Click to sttatch rubber bands to both and hang them from your dash :)

There are still a lot of bugs, especialy in Drag mode, so they are being worked on.

11310 views / 19 in the last 7 days

25 votes | 0 in the last 7 days

Tags: mouse simulation physics with-source

This scenario is a member of: Reusable actors & support classes


open in greenfoot
Your browser does not support the canvas tag.
mjrb4mjrb4

2009/10/5

Hi - the best course of action would probably be for you to head over to the discuss group (http://groups.google.com/group/greenfoot-discuss) and post it there as a file along with an explanation of your problem, then we can have a look at it. I guess there's a chance this might be windows 7 specific, especially since you're using a beta and not the final release which has been out a while now... :-) Have you tried it on another OS just to be sure?
mjrb4mjrb4

2009/10/6

Hmm, whilst dragging the dice around every so often it freezes up and I get the following message in the console: overload!! overload!! overload!! overload!! overload!! overload!! overload!! overload!! overload!! overload!! ...never seen that before! Is that something you've put in your code or is Java doing something rather special?
Hi Mjrb, and Sorry BlackholeGF, I don't check my email that often so i didn't get to your question in time. Mjrb gave the right advice! :) As for the Overload message, it was something I programmed in to output under special circumstances of the simulation. It occurs when there is an error calculating the Surface Normals, and they become much larger than suposed to, so until I figure out how to fix it, I outpul Overload!!! And reset the normal to zero, hence the weird movement. It seems to happen when corners colide.
mjrb4mjrb4

2009/10/6

Ahh sure that makes more sense. Just wanted to check it was that and not the JDK being weird (I was giving the early version of 7 a stab for a number of unrelated reasons.) I haven't looked at the code so this might be way off, but would it be to do with the corners overlapping too much before the collision is detected? If so then one methodology might be (if you're modelling it in a time based way) to step back and forth until you calculate the exact collision point then calculate the normal sizes from there. So say you've advanced t time between the last frame, computationally step back to t/2, check if that's the collision point, if it hasn't collided yet step to 3t/4, if it has step to t/4 - and then work that way. That may be completely irrelevant so apologies if that's the case but I thought I'd throw it in there in case it helps! Great work as always though, I always get a bit excited when you post something new :-)
YoinkinatorYoinkinator

2010/2/6

Hm, how come there is no horizontal movement when the blocks hit walls while spinning?
Because friction is not fully implemented during collisions. It IS implemented however wrong, which is why the blocks don't slide around a lot though.
mjrb4mjrb4

2010/2/6

Just out of interest, have you thought about ways to solve the classic stacking problem? :-)
Yeah, most likely the best thing to do would be to rewrite the engine completely using momentum and torque rather than deformation and springs. The way the physics is calculated right now is very hacky x.x
NiyxNiyx

2011/1/4

Amazing! I could spend hours playing around with stuff like this. Keep the good work up.
KartoffelbrotKartoffelbrot

2014/1/26

How do you differ if a box hits another from above or right if one box hits the other at it's corner? Like this: |=====| |=====| |=====| |=====| |=====| |=====|

See all comments

Want to leave a comment? You must first log in.

Who likes this?

nachocab Entity1037 Oldmoe Kartoffelbrot JetLennit SPower FlyingRabidUnicornPig Reflection JavaForever jrlowe Moritz thegreencoolerman SirFoxie Niyx haxxpop mik markoni MathManiac TheJH MTK