Game Development Community

Best class for ball that bounces/rolls/flies?

by Joseph Villard · in Torque Game Engine · 09/22/2004 (7:53 am) · 15 replies

Hey, guys, I am at a critical stage in my current project - the development of ball physics and basic gameplay - and I reallly need some advice. I have tried to figure out what to do, but have experienced several problems I couldn't get past.

The ball is like any sports ball - a soccer ball, a baseball, etc. It is launched into the air like a soccer ball, it spins in all axes and curves due to spin. The ball bounces and eventually comes to rest. Depending on how you hit it, it will roll only, or bounce then roll. It acts differently on different surfaces and flies differently in a strong wind. It will never explode, and in fact, I hope it will stay around and never dissapear.

I have tried:

Basic projectile: This worked okay, but the bouncing issue is a REAL big problem. After 2 or 3 bounces, it flickers back and forth in one place. Also, I can't figure out how to make this persistent. Also, how do you incorporate wind, which is a skybox member?

ShapeBase object: the docs say that Marble Blast used this object for its marble. The difference is that in my game, the ball is not the main character. Does that matter? I haven't yet tried to implement line-swept ball rolling like they did in MarbleBlast, but I don't know how I would incorporate the appropriate projectile motion.

Any hints/suggestions on the appropriate class? Or what my new class should inherit from? I have the SDK and have been messing with the engine, so I am not afraid to get my hands dirty. Anyone done this before? Oh, and any inside info on MarbleBlast would be appreciated:).

Thanks,

Joe

#1
09/22/2004 (8:10 am)
Take a look at my Rigid Shape resource.

Afaik Marble Blast marbles were _based_ off shapebase objects (just like almost any shape), but its not only a shape base.
#2
09/22/2004 (8:12 am)
Howdy Joseph, check out This Resource. I think it's what you're looking for. Our team was looking to implement a 3rd-party physics library until we came across this resource. Hard to believe it had always been in Torque, but no one ever took advantage of it before. ;)
#3
09/22/2004 (9:15 am)
Thanks for the info, guys. You both recommended the same resource so it must be the way to go. I watched the movies to see what was going on and the "boulder" is exactly what I have in mind. Except I would add a few things for projectile motion.

Man_of_Ice, thanks for such a great resource. BTW, what exactly did you do for the rolling boulder? Line-swept collision detection? Any code you found on the net for this? Oh and getting the skin to roll with the ball. Was that hard? Any addt'l info would help a lot.

Thanks, again,

Joe
#4
09/30/2004 (8:29 pm)
First off, awesome resource...

Second, I too and looking to implement a "ball" of sorts and think the rigidshape code looks like a great start for what I need.

However, I'm pretty much just starting with torque (even though I have had it for awhile), and I am having trouble getting the rigidshape to show up in the mission editor.

I followed your resource word for word... the only part I am a little confused about is where to put the datablock RigidShapeData( BouncingBoulder ) code. I tried placing it into the same .cs file where my function RigidShapeData::create(%data) code is, but I don't think it is working.

In the console file, I get the warning \torque\engine\console\consoleobject.cc @ 62) Couldn't find class rep for dynamic class: RigidShapeData
and
/server/scripts/ball.cs Unable to instantiate non-conobject class RigidShapeData

Any help or nudges in the right direction would be greatly appreciated.
#5
10/01/2004 (12:15 am)
Did you remember to exec() the script containing the RigidShapeData? Usually done in server\scripts\game.cs
#6
10/01/2004 (8:38 pm)
Yup, I exec it in the game.cs file. I have both the datablock RigidShapeData(BouncingBoulder) and the function RigidShapeData::create(%data) in the file I exec. I kept everything in those two function identical to your tutorial, except for the location of the shape and the name of the file itself (it is named ball.cs).
#7
10/02/2004 (2:55 pm)
Wow, this resource really got me on the right track.

One more thing: I would like this rigid shape to move in a projectile manner, but when I give it a good impulse directed upward, it goes nuts. Is there anyway I can use the projectileData object in conjuction with the rigid shape object. Anyone have any suggestions on how would I get started on that?

Thanks,

Joe
#8
10/02/2004 (11:22 pm)
@Jeremy: sounds to me like the rigid stuff never got compiled into your engine exe. But I've never seen/heard about that problem before. And run through the resource again to make sure you did exactly as written. It works, so you must have missed a step / the resource description is missing an obvious step that I took for granted

@Joseph: TGE rigid/vehicle physics is notorious "problematic" at high speeds with collision. I dont think you can use it for high speed projectiles, and you need to work from vehicle datablocks - not projectiles
#9
10/08/2004 (9:12 pm)
Recompiled it, and made sure I saw it build the rigid.cc file... still having same problem.

In the guide it says "If you want to do this "for real", then one also needs to define a new objectType. I have reused the ShapeBaseObjectType - change that if you want or go through tons of code and add a RigidShapeObjectType."

Now, does that mean I need to add a new object type or change it to reuse ShapeBaseObjectType? Or should it already be set up that way?

Also, is it ok to have the datablock RigidShapeData in the same .cs file as the create function?

Sorry to be so clueless... like I said, I'm very new to Torque (even though I've had it on my machine for a year) and I'm trying to dive right into it so any help with getting this to work would be awesome.
#10
10/27/2004 (5:25 am)
I am having the same problem as Jeremy, was this problem ever resolved, if so how if not then how too i guess.
#11
10/27/2004 (6:11 am)
Hey, guys,

After adding the .cc and .h files to the engine (1.3.0) and doing a CLEAN rebuild, I added (RigidShape.cs) to my project in server/scripts and added exec("./RigidShape.cs"); to my game.cs. It worked after doing that. Rigid shape containsa datablock and a create function straight from Man of Ice's resource.

Also, if you add the onCollision stuff, you should increase the strength of the impulse or the boulder won't move.

Good luck. Joe
#12
10/27/2004 (6:28 am)
Thanks that works great. At the risk of exposing my foolishness in the hopes that it helps someone else out, when he says add to project i took that to mean put it in the server/scripts folder. What needs to be done is add it to your project in visual studio or whatever you are using to compile. Thanks for the help again.
#13
10/27/2004 (9:06 am)
I'll edit the resource and write it more clear :-)
#14
11/13/2004 (9:17 pm)
Heh ok, I really must be missing something easy :(

I've removed everything I added, then re-added it all following the instructions and I still get the same problems. I have added the .cc and .h files to the project, and I have compiled it, and I do see it in the build window in visual studio telling me it built rigid.cc, and there are no build errors.

Now, with the console error I get when trying to run the app "Couldn't find class rep for dynamic class: RigidShapeData" it sounds like it can't link the datablock to the compiled class. My question is this... how is Torque supposed to associate the datablock to the Rigid class when the datablock itself doesn't seem to reference it at all? Is "RigidShapeData" supposed to be found somewhere else... since I don't see it in the rigid.cc or rigid.h files at all.

I would think RigidShapeData should be defined somewhere in the compiled code, and that the RigidShapeData datablock would then access it... but maybe I'm thinking about it all wrong :(
#15
11/14/2004 (9:39 am)
Have you done a clean rebuild?