Game Development Community

Rolling sphere?

by Chris · in Torque Game Engine · 06/25/2005 (6:44 am) · 20 replies

I'm just playing around with the engine and have attempted to drop a sphere into the game for the player. Built the model, got it into the game, but I've noticed something funky that it sinks half way down into the ground. I can still move around the terrain, but half the sphere is below the surface, half is above.

Someone in IRC suggested that I make the sphere a vehicle class instead of player class, but being newb the more I looked at the vehicle code, the less I thought I'd be able to figure that route out :)

Any thoughts?

#1
06/25/2005 (9:13 am)
The player's bounding box is set in its datablock. Try messing with that a bit to see if it helps out. The player and item classes only use their bounding box for collisions, so that could very well be your problem.
#2
06/25/2005 (9:57 am)
.
#3
06/26/2005 (6:49 am)
Hmm, I tried a few of those. Dupe'ing the model and naming it Collision_1 and it didn't change anything. Shifting the model up above the origin seemed to work fine. Though from the 1st person POV it's still goofy because I need to figure out the eye node.

I'm beginning to think even though it's more work, it may be easier to use a vehicle class.
#4
06/28/2005 (8:22 am)
Turn the sphere into a vehicle (you might need to make a new vehicle class or you could probably make the sphere a wheel for a nonexistent car) and find the line in game.cs where it says something like this.

%player = new Player() {
dataBlock = PlayerBody;
client = %this;

and change it to

%player = new wheeledvehicle() {
dataBlock = sphere;
client = %this;

that will spawn you as the sphere and not an orc

if you copy car.cs from starter.racing into server/scripts and get its images into data/shapes you could test it out with that. then the game.cs line would look like this.

%player = new wheeledvehicle() {
dataBlock = defaultcar;
client = %this;
#5
09/08/2008 (9:25 am)
Alrighty. This is an old topic but Im reviving for everyone's benefit.

Now What I did was replaced the buggy with an invisible object inside of 3ds its got a bounds box, col, its got the cam, eye and hub0 setup.

I replaced the TIRE used by the buggy with my gameball.dts The rolling of it was really screwed up so I changed the pivot point of my gameball BACK to the center, but its falling halfway through the floor again, so does this mean i need to add collision to my gameballl now thats it acting as a wheel OR can i simply change my player object into this wheel version of my gameball??

To go a little more in depth, whats happening is the car object that is basically only a collision mesh and a bounds box andd the eye, cam, and hub0. But when ti comes into the world it falls off the platform i have as my spawning point. What we TRIED to do was have an invisible ccar object and just having a car wheel spinning, but the cam gets screwed up every time since its based off the invisible car object and when i roll the ball, which does roll nicely, but it doesn't go anywhere.

ALSO is there a way to add or change the physics in order to add a sideways motion?? The over all mission is to have a ROLLING ball and so far it roll BEAUTIFUL with forward, back and diagnol directions. Can I add a side to side roll?

Also I tried setting the player object to be set as the DefaultCarTire and basically when it tried loading the world it kind of stop right when it got to loading objects.
#6
09/08/2008 (10:13 am)
Good to see you're making progress with your project Archon. I'm not sure I fully understand your question, are you using the player class or wheeledVehicle class for your rolling ball?

For getting your vehicles wheel to roll sideways, I believe there is a function you can use(something like "setWheelSteering") to allow your wheels to go 90degrees, or whatever amount you want. That may do what you are looking for. It should be in the scripts.

Also, since you're doing a lot of work on the wheeled vehicle, tweaking datablocks and whatnot, I would recommend adding a realtime datablock tweaker to save you from having to exit, delete DSO's, etc. etc. You could use the plastic tweaker that plastic games has released (haven't tried it, looks great though), or use thishack (at bottom of post)
#7
09/08/2008 (10:37 am)
Well J.P. Berry Basically Im trying to get my player object to be my rolling object. But before I was having problems with animation snapping so it didnt look nartual.

So an instructor of mine told me to maybe treat this ball i have made as a wheel.

What I would like to do, which is the easiet way but it didnt work, is simply make the datablock = sphere tp be datablock = DefaultCarTire;

It didnt work it stopped when it got to the end of Loading Objects inside of Torque.

So Instead I made a custom car object there was no mesh, so basically we were treating my gameball as a tire and hooking it up to a non existent mesh that had collision and a bounds box, and we hooked it up to hub 0. And we cant simply make the other 4 wheel invisible andd just use one visible one because this game ball of mine is jumping from platform to platform and going through puzzles.

Thats my overall goal. If your interested or need a clearer picture I could perhaps send you the folder zipped up?? This is a school project. I have no reservations about sharing or showing it.
#8
09/08/2008 (1:25 pm)
Well, the way you are going about it is a round-about way, that should work decently with some tweaking. I believe Marble Blast created their own class, derived from shapebase.

You may be able to use the wheeled vehicle class, with some hacks involved. Try splitting your sphere in half, and connecting the halves with your vehicles front axle. So this way your left wheel is your left sphere halve, and your right wheel is your right sphere halve. Then create two small wheels (or none at all if you can get away with it) that are invisible in the back.


Does that make sense at all? This is a dirty way of creating it, but less complicated then coding your own shapebase class with custom physics. Are you comfortable with C++? If so, you could modify the wheeledVehicle class to suit your needs. Or just jump straight in and start your own shapebase class like they did for Marble Blast

www.garagegames.com/docs/tge/general/ch02s05.php
#9
09/08/2008 (1:58 pm)
Well I just hope that I am being clear on what I want to do i nthis game.

Im not all that comfortable with c++ I do find scripting for Torque 3d to be very fun and Im sure I will go after a more in-depth education on it after I am graduated.

But anyway, I get what your saying and I doubt I could successfully code my own physics at this time. Your idea sounds intriguing, but my question would be that this is a platformer puzzle game in a 3d setting so what if the front wheels, or rather my "ball" jumps onto a platform but the back wheels that are invisible fall off the back of the platform along with the object I have setup for my invisible car. Wont the vehicle be pulled off the platform? Before I got one wheel or rather my ball object to show up on hub0 but it didnt roll anywhere except in-place since the other wheels weren't there.

I wish there was a way to just have the wheel itself be my playerobject and have the physics of the wheel be present without the influence of the car lol too bad.

I wish i could just contact the guys who made Marble Blast. I don't think I approached too aggressive of a project I just don't think there is sufficient info out there for people who are new and like trying to do things with an FPS engine that aren't normal heh.
#10
09/08/2008 (2:43 pm)
Unfortunately I am not knowledgeable enough in the wheeledVehicle class to be of much help. Just keep playing with it, I think you are on the right track.

There is a bike/motorcycle resource that only uses two wheels/hubs. It is located here. I also noticed it has the variable I mentioned for wheel angle :
maxSteeringAngle = 0.785;  // Maximum steering angle, should match animation

Maybe you can play with that and connect those two hubs together, or try and get away with only one hub. If you do go with four wheels, maybe see if you can align the rear axle/wheels parallel to the front axle. That way you wouldn't be dragged backwards, as in your above example.
#11
09/08/2008 (2:57 pm)
Archon
Just an idea, but have you looked at the rigid shape class for your sphere?
once the datablock is set up right (and you have a sphere dts with a sphere collision mesh), you can move it around with impulses, but that may cause issues with the default camera (you would prob need the advance camera). just another route you may like to try.

good luck with your project.
#12
09/08/2008 (4:39 pm)
Archon
I'd stick to the player class and work on your animations. Here's a very quick and dirty
example:

sphere movie

and here's the Milkshape file:

sphere player files

There is a roll back one way or another when you come to a stop (the animation
resetting to the root animation) but the advantage of staying with the player class and
merely replacing out the model gives you all the advantages of the player code without
having to change just about anything. This particular MS3D file only has the forward
animation (I'm knee deep in a bunch of things to do all the animations, but from this it
should be pretty straight forward on the others).

Basically you need a little scripting to modify the side animation (i.e. side_left and side_right)
and could probably do some type of animation on key release based on forward, side or
backwards direction to eliminate the "snap to root" that would be something like a rotation
in the same direction to a stop.

If this is where you've already been, sorry for not moving you forward, but hopefully it
helps a little.

Alan
#13
09/09/2008 (8:44 am)
I'm confused by your explanation. How exactly do I eliminate the "snap to root" The way you explained it was really confusing. And when you say replacing the model, what do you mean??
#14
09/09/2008 (3:53 pm)
Hey Archon, I'll try to elaborate, but the solution to this does involve a certain level of complexity,
at least as far as I can tell.

Ok, we'll start with the model replacement first. The sphere.zip file above includes an example
of sphere that has two animation states, 1)root 2)run that has the default player.dts name.

If you replace the orc player.dts with this player.dts (make a copy of the orc player.dts first) it
will be the new player -- a sphere -- and will run the "rolling" animation when you "run" forward
and revert to the root animation "stopped" when you release the "W" key, i.e. your forward key.
This is just a quick example that I made, without the "back" and "side" animations, but you get the
point. All of your movements would be animation sequences which are really just a rotation of the
sphere either forward, back or left side/right side.

By default the side keys (A and D) run the same animation with the orc model, that is the "side"
animation. You would need to add two different animation sequences bound to the A and D key
press to run something like I mentioned, a rotation left (side_left) and a rotation right (side_right)
to keep the sphere from rotating the same direction with the left or right key press
(A or D respectively).

This will require a little bit of scripting and it's a bit beyond what I can lay out for you,
but there are quite a few folks here who should be able to walk you through binding a
key to a particular animation sequence.

The animation by default "snapping" to the root sequence problem is pretty straight forward,
but the solution might be a little complicated. The problem is that when you release a
direction key -- A S D or W, the "rolling" animation will stop and the "root" animation
will instantly play. That's fine if the rotation of the sphere happens to land close to the
stationary frame of the root animation, but if it's one way or another (either ahead or
behind the root) then it will look weird and suddenly roll backwards or forwards abruptly.

One way I could see solving this is to also add to your sphere model four more animation
sequences that would be a forward to stop, back to stop, left to stop and right to stop.
Basically these would entail a few frames that brought the sphere to a stop in the direction
that it was moving.

You would need to determine the state of your "player" i.e. is he moving forward, back, left or
right and then determine the state of your keys. With these two know variables you could
trigger these specific animation sequences.

Let's say you are "rolling" forward, then lift the key press on "W" (key up state) then the
forward to stop animation would play, followed by the root animation. This should eliminate
any snap to root problem. Again you would have to add to your key binding script code both
the key down and key up state variables, something like this (this isn't complete, but is just
an example of the idea);


function myFunction(%val) {
if (%val == 1)
//The key is down
if (%val == 0)
//The key is up}


Then you would need something like if(%val) { Then do animation }. I'm sorry I can't
elaborate on the script to do all this, I'm an artist and not a coder. Hopefully someone with
a lot more coding experience will chime in here for you and correct anything that I might be
in error about.

Good luck,
Alan
#15
09/09/2008 (4:27 pm)
If you are going with the player class, one way to remove the snapping to root problem is to remove the root animation and it will hang on the last frame of what ever animation was last playing. using the side animations should work as the right ani plays the left ani in reverse, but it can be replaced in the engine to use a left ani if needed easily.

you may want to look into using the orbit cam and the "Player Movement with a Separate Camera Object" resource as then the player will move up,down,left,right relative to camera with just the run animation.


just some ideas..... hope they help.
#16
10/06/2008 (8:37 am)
Well its a new quarter and still with the same problem. Trying to get my ball working based of velocity or some form of physics instead of my current snapping animation. A coder friend of mine suggested starting with physics algorithms but thats definitely greek to me. Im wondering if anyone can suggest a good starter material, book wise to forming my own physics based off velocity. Im definitely not looking for a quick fix because in reality its not possible and everything else so far either hasn't work or not produced a desirable affect. If anyone has any advice please do let me know. The worst part is in this program I am in 11 weeks isn't a whole lot of time to really work out something this complex.

Thanks so much.

ArchonLight
#17
10/06/2008 (11:01 am)
Hey Archon,

What problems are you still coming across? I think Alan Jame's solution seems like the most straightforward, and wouldn't involve any physics changes. Do you not like how the player's class physics behave? Or is it only the way the animations play that you do not like?

If it is only the snapping to root animation problems that you are not content with, I think it would take less time to fix that then to code your own physics. But, that's just my opinion, and learning new concepts is never a bad thing.

I think this resource may be of some benefit to your project. Read through the code and see if you can incorporate the ideas into your project.
#18
10/06/2008 (12:02 pm)
Well the problem that i stated before is that i have a rolling ball for my main character and i have its animations set, but for instance when i go any direction and let go of the button midway through the animation it snaps back to the idle animation which looks pretty horrible.

So far I've tried treating the ball or sphere like a wheel from a vehicle since it has movement based off of velocity which seems to be the way to go for a ball. Unfortunately it hasn't worked so far, and with the model i WANT to use i can't have a solidly colored ball since the modle isn't perfectly spherical it has been modified in 3ds to give it a more unique look.

So the goal is to get a rolling ball as the main character and so far it is in my game it moves and it rolls to a degree but unfortunately the animation snapping is a problem, wish i could capture some footage to show you what is going on in game.
#19
10/06/2008 (1:19 pm)
Well the problem that i stated before is that i have a rolling ball for my main character and i have its animations set, but for instance when i go any direction and let go of the button midway through the animation it snaps back to the idle animation which looks pretty horrible.

So far I've tried treating the ball or sphere like a wheel from a vehicle since it has movement based off of velocity which seems to be the way to go for a ball. Unfortunately it hasn't worked so far, and with the model i WANT to use i can't have a solidly colored ball since the modle isn't perfectly spherical it has been modified in 3ds to give it a more unique look.

So the goal is to get a rolling ball as the main character and so far it is in my game it moves and it rolls to a degree but unfortunately the animation snapping is a problem, wish i could capture some footage to show you what is going on in game.

Also in all honesty Alan James' solution does seem accurate and viable its implementing it that confuses me, but in truth I just had a week off from school I relaxed a bit so now my head is back in the game so to speak.
#20
10/20/2008 (2:26 pm)
So I think this would be the code I need to modify. Basically instead of making my own physics I can go inside the engine and stop it from automatically going back to the root animation correct? That should allow for the ball to have a little more of a free look and stop the ball automatically snapping back to root if I stop moving. If anyone has a good idea of what Im talking about or know that Im on the right track please let me know.


// Player shape animation sequences:

// look Used to contol the upper body arm motion. Must animate
// vertically +-80 deg.
Player::Range Player::mArmRange(mDegToRad(-80.0f),mDegToRad(+80.0f));

// head Used to control the direction the head is looking. Must
// animated vertically +-80 deg .
Player::Range Player::mHeadVRange(mDegToRad(-80.0f),mDegToRad(+80.0f));

// Action Animations:
PlayerData::ActionAnimationDef PlayerData::ActionAnimationList[NumTableActionAnims] =
{
// *** WARNING ***
// This array is indexed useing the enum values defined in player.h

// Root is the default animation
{ "root" }, // RootAnim,

// These are selected in the move state based on velocity
{ "run", { 0.0f, 1.0f, 0.0f } }, // RunForwardAnim,
{ "back", { 0.0f, -1.0f, 0.0f } }, // BackBackwardAnim
{ "side", { -1.0f, 0.0f, 0.0f } }, // SideLeftAnim,

// These are set explicitly based on player actions
{ "fall" }, // FallAnim
{ "jump" }, // JumpAnim
{ "standjump" }, // StandJumpAnim
{ "land" }, // LandAnim
};