Game Development Community

Riged Shape Example

by Mike Rowley · 08/17/2008 (6:59 pm) · 16 comments

Round 2. The first one got lost in the abyss of GG.

Do to several people on the forum looking for examples on how to implement Rigid Shapes in Torque, I put together an example. This isn't a tutorial, but has 3 different types of shape files included. I used the standard starter.fps example to implement this. I'm hoping that the scripts will work as good starting points for people to figure out how Rigid shapes work.
Included in the zip file are the following:
3 different scripts, 1 shapes folder with 2 shapes, and a mission file for starter.fps with the Rigids added, and a movie. (same one as below)
If you don't want to use the mssion file, you can add the objects thru the object inspector. (you may have to raise them above ground after placing as they tend to bury themselves. Just save after you raise them)

The scripts and objects I got from resources and others helping me here on the forum. I didn't write down who I got them from, so if you recognise these, Please take this as my "Thankyou". They have helped me a lot, and hopefully, they will now help others.

Anyway, what's a blog without a movie?


OOPS. Edit to add download link. [url="http://3dcentral.net/downloads/torque/tutorials/RigidShapeExample.zip"] Download from here[/url]

Edit #2 Since the download link doesn't want to work, here is the url to copy/paste. http://3dcentral.net/downloads/torque/tutorials/RigidShapeExample.zip

#1
08/17/2008 (7:25 pm)
Great work!
#2
08/17/2008 (7:31 pm)
Sorry, forgot the download link. :blush:
Thanks for the compliment.
#3
08/17/2008 (7:38 pm)
Thank you sir. This is something that should have been part of the GG tutorials from the get go.
#4
08/17/2008 (7:40 pm)
Can this work for TGEA?

Great Job
#5
08/18/2008 (1:41 am)
@Kory

Yes, RigidShape has always been in TGEA.
#6
08/18/2008 (7:24 am)
For TGEA just check that the file gets loaded in your project.
//in game.cs
   exec("./rigidshape.cs");

(I think I'd taken mine out by mistake!)
#7
08/18/2008 (8:46 am)
Awesome Mike, thanks for coming through on this one.
#8
08/18/2008 (8:52 am)
I've noticed the cube falls into the terrain and both the boulder and cube fly off unrealistically sometimes. Is it possible to clamp these down?
#9
08/18/2008 (3:33 pm)
Quote:I've noticed the cube falls into the terrain and both the boulder and cube fly off unrealistically sometimes. Is it possible to clamp these down?

I've never been able to figure out why that happens. It can be a lot of fun "launching" them into space if that's what you want to do, but most people would want a more realistic behavior. I just haven't figured out how to achieve that.


@ Steve

I don't have a rigidShape.cs in my game. Just the 3 included and it works just fine. (with ecception of the afforementioned launching at times)
#10
08/18/2008 (3:55 pm)
I think the launching maybe something to do with collision not resolving entirely on objects and then getting another impact velocity on it causing it build exponentially.

As for the object falling throught the terrain perhap tesselating the cube might solve this problem.
#11
08/18/2008 (5:57 pm)
@Mike: the rigidShape.cs is included in the demo scripts, it's the bouncing boulder example. For player interaction (push, pull, etc) it needs an onCollision callback. I suppose GG's idea was to demonstrate that it could bounce and roll downhill but never implemented in in the demo or added it to the starter.fps scripts.

You can also add a density setting to your datablock and make it float/bob in the water, if the density is less than the water's density.

As far as realistic behavior goes, that will involve balancing of mass for both the collider and object, tweaks to the other datablock properties, careful application of impulse, possible changes to the physics methods in source code, and keep in mind that the collision mesh shape has a lot to do with the behavior of how your objects bounce, roll, slide, etc. It's pretty freaky to walk up and knock a barrel over, bump into it and watch it roll, and then it stands back up!

To prevent collision response from building exponentially, just track the objects last collider & get the simTime from the latest collision. And if the last collider hits it again in say less than half a second, then return out of your onCollision callback.
#12
08/18/2008 (6:14 pm)
> most people would want a more realistic behavior. I just haven't figured out how to achieve that.
this has always struck me as a common problem with the rigid shape stuff.
#13
08/18/2008 (7:48 pm)
Thanks for the answers Mike. :-) Some things I didn't know. (bouyancy)

Orion, if you look at Marble Blast and Rocketball, you will see that you can get some really realistic behavior from Rigids. I don't know enough about it to give a good tutorial, so just gave the examples I've been using. I'll have to take a look at the bouyancy settings, and mabe play with the collisions a little to see what I can come up with.
#14
08/19/2008 (12:33 am)
I for got to mention that you should be careful with the density setting. If you set it too low it will fall into the water...sink, and then shoot up into the sky. Funny of course, but not very realistic. I'm using a ratio of density = 0.975 to the water density being 1, and it works quite well for barrels and crates type objects, but mass could play a factor in that also, I'm using mass = 100 as that gave me a decent believable effect with explosion impulses.

And for the collision time checking put something like this in your onCollision callback:
// do your collision checks for self and the terrain
// ...

if (%obj.lastCollider = %col)
{
    // we just ran into this, lets give it half a second before we apply another impulse
    if (getSimTime() - %obj.lastColTime < 500)
        return;
}

// do your math calculations, vectoring, applying impulse, etc.
// ...

%obj.lastCollider = %col;
%obj.lastColTime = getSimTime();
#15
08/19/2008 (9:48 am)
Mike, very cool work man, I'll play around with this and see what I can do with it. Learning something new every day with torque... Working download link for those its not working for:

http://3dcentral.net/downloads/torque/tutorials/RigidShapeExample.zip

Great work man,

Will
#16
10/11/2008 (10:32 pm)
Has any got a good example .mis/rigidshape file for bouancy? I have been playing around with Rigidshape all day and have gotten familiar with it some except I would like to have a object hit the water and float. No luck so far, chaging density/velocity/mass on the waterblock and the boulder have no effect. I have found several snippets, but nothing showing a completed working scenario.