Game Development Community

[RESOLVED] How to mount wheels to Vehicles ?

by Scott Warren · in Torque 3D Beginner · 12/29/2012 (6:36 pm) · 16 replies

Been around for a long time and never really needed to know how to mount wheels to a vehicle.
But here I am, working with T3D 1.1 and 1.2 with the Cheetah vehicle. But I have no idea how to go about mounting the wheels to it.

#1
12/29/2012 (7:26 pm)
Are you having problems art related or with script?
#2
12/29/2012 (10:52 pm)
game\scripts\server\cheetah.cs

function CheetahCar::onAdd(%this, %obj)
{
Parent::onAdd(%this, %obj);

%obj.setWheelTire(0,CheetahCarTire);
%obj.setWheelTire(1,CheetahCarTire);
%obj.setWheelTire(2,CheetahCarTireRear);
%obj.setWheelTire(3,CheetahCarTireRear);

...........
.
.
..

}

Quote:
bool WheeledVehicle::setWheelTire ( int wheel,
WheeledVehicleTire tire
)

Set the WheeledVehicleTire datablock for this wheel.

Parameters:
wheel index of the wheel to set (hub node #)
tire WheeledVehicleTire datablock

Returns:
true if successful, false if failed
Example:
%obj.setWheelTire( 0, FrontTire );
#3
12/29/2012 (11:02 pm)
I don't know where to begin to attach wheels to a vehicle.

Being a common sense sort of guy, I went searching for the method used to get the wheels attached to the Cheetah body. But I am missing the thread I guess.

It seems natural to me to think that If I spawn a Cheetah body into the game environment, and then spawn a few wheels that I could manipulate them to attach to the Cheetah.

I read somewhere that the wheels were being mounted in the Object Editor.
Read more posts about problems dealing with mounting the wheels, as well.
But none of the threads I have found to read, actually point out the method of attaching wheels.
I don't mean having the mounting nodes, nor the scripts. I mean the physical attachment.
#4
12/29/2012 (11:40 pm)
It must be late, I still don't understand what you mean.

In Menu -> Shape Editor (This can be a great tool, wheels sometimes come in with their pivote points backwards)

Once you load up the Cheetah body, hit the "toggle advanced properties window". Go to the "mounting" tab, and browse for a wheel. Select a node to mount the wheel to.
#5
12/30/2012 (12:27 am)
Quote:I don't mean having the mounting nodes, nor the scripts. I mean the physical attachment.
Not sure I understand what you're getting at. Attachment is done via scripts, unless you just want to play round with the Shape editor.

Quote:It seems natural to me to think that If I spawn a Cheetah body into the game environment, and then spawn a few wheels that I could manipulate them to attach to the Cheetah.
That's unfortunately not how wheels work. Ahsan pointed out above how you go about attaching tires in scripts. You don't actually create a wheel object and mount it to the vehicle, you just specify the tire data block that should be used at a given wheel hub. There is no separate object created; the Vehicle itself renders the tire meshes.

You can do what you're saying - spawn a body, spawn some wheels, then attach them - using mountObject. However, wheels mounted this way won't spin or steer with the Vehicle.
#6
12/30/2012 (5:41 am)
I know it seems like a strange question to those of you that understand it and you've done it... and any other method outside of what you know to be obvious to you would seem strange :-)

However, when a person like myself, sits to read books, scripts, and engine code, and then moves on to Modeling and Animation for the majority of time spent in Torque... It's not so obvious because the actual work is not being performed and the manuals do not directly point out that to get the wheels that I just Modeled and Animated to be attached to a Vehicle, that they need to be "Script Applied" as in they are auto-applied through the exec of a script. I've found no such comment or indication... or the method simply wasn't clear to me, if it was presented.

I am quite familiar with the script section that Ashan pointed out, I've probably read that script a dozen times.

I've read that each wheel, up to 8 by default without engine modding, can each have their own Datablock.
I've read that each wheel can be powered or un-powered.
These are script options and I can achieve the results I want from any of the wheels by clever scripting, but the method to apply them was always a mystery to me since I never really needed to apply them myself.
#7
12/30/2012 (7:19 am)
The object's Class has certain functions that do the autoMagic 'mounting' of wheels.

In the quoted portion of Ahsan's posting lies the 'magic'....

Parameters:
wheel index of the wheel to set (hub node #)
tire WheeledVehicleTire datablock

Returns:
true if successful, false if failed
Example:
%obj.setWheelTire( 0, FrontTire );

You create datablocks for each 'tire' you want; either for differing art assets or 'behavior' of the object.

These datablock descriptions are needed by the Wheeled Vehicle class...because they are the 'wheels' the vehicle mounts to the chassis. In this small line of scripting, "%obj.setWheelTire( 0, FrontTire )", all the work is done.

1. The "%obj" argument is the wheeled vehicle object needing wheels mounted.

2. The "setWheelTire" function does the actual 'mounting' of the object to the 'hub' node.

3. The "0" argument is the HUB node's position/location on the vehicle object. In this scripting above, the wheel will appear on the HUB node named "0"; this corresponds to the Driver side Front wheel location for a Wheeled Vehicle object.

4. The "FrontTire" argument is the datablock name in scripting for the appropriate 'wheel' object; that which you created to point to the correct art asset for the intended object.


I hope this makes some sense of the process for mounting wheels to vehicles. You NEVER animate the wheel art asset[turning 'round]!! That is done by C++ code for the object. I have animated the suspension for the "hub" node to have a vehicle have a more realistic experience. This included rising/falling suspension parts, as well as an offset in node placement for 'steering' the wheel.

Vehicles are fairly complicated to get working; you need 3 separate scripts: VEHICLE datablock, TIRE datablock, and SPRING datalbock. Then you need the 2 separate art assets: VEHICLE chassis geometry & TIRE/WHEEL geometry.
#8
12/30/2012 (7:40 am)
Thanks to all of you, the pieces I read prior to this post, and your explanations have cleared the fog for me.

With all the responses for the thread, I feel confident that I can get this to work for me.
To clarify the animation of the wheel, I was speaking of special effects like for my airplane.. the animation to pull the wheels up to the wings when in flight, but I am grateful that you still pointed out they don't actually get an animation otherwise.

Now with all the details I think I was missing, I can get to working.
Much appreciated guys.

P.S. @Britt Scot:
The Xbox 360 Controller "rumble" does work and I updated that thread to let you know.
I'll be using the Xbox Controller resource together with this information.
#9
12/30/2012 (10:47 am)
@Scott: glad the rumble worked.
#10
12/30/2012 (1:04 pm)
@Rex, so that it is clear to me... it's just 1 script with the 3 datablock types placed in ./server/Cheetah.cs ?
Then the VEHICLE datablock, TIRE datablock, and SPRING datablock are in the single script, right ?
And I need the art assets for the vehicle body and wheels as seperate *.dts files.

I ask for clarity because you mention 3 scripts.. I think that was a typo?
#11
12/30/2012 (2:44 pm)
Yes; not 3 script files[binaries] but 3 areas[dataBlocks] that need scripting, mea culpa.

And yes, 2 separate geometry binary DTS or DAE files, wheel and chassis; the 'spring' datablock has no associated geomtry[that I know of] but it's the 'link' between the other objects and is needed for stock wheeledVehicle behavior.

...now you can have suspension/spring geometry included in the vehicle; just make those parts part of the 'chassis' binary. If you can; look at the SDK vehicle source file and see how they accomplished this part, what parts are included in the 'vehicle'.
#12
12/30/2012 (2:55 pm)
And to make it even more confusing, the datablocks are declared in one script file (in art/datablocks), and the functions like CheetahCar::onAdd are defined in another file (in scripts/server).
#13
12/30/2012 (3:47 pm)
Ok. This is all good to know. Thank you.
I had the feeling there was a second part, I didn't think it could be just a single script under the server folder.
If there was a tutorial for this somewhere, it doesn't come up with my search or I simply missed it.

The help you guys gave, clears up a lot of the book knowledge that was missing.
#14
01/02/2013 (11:29 am)
I've built a new vehicle and tested the wheel mount hubs in the Object editor, which seems to work as intended.

I'm up to the point now that I'd like to edit the scripts.
I went to ./art/datablocks/cheetah.cs and ./scripts/server/cheetah.cs and scriptExec.cs to open them.
[EDIT] Looks like vehicledWheeled.cs is also included.

Are these the only 3 files that need to be modified when I want to make a new vehicle?
I've modified those 3 files and shut down the engine, I then restarted the engine and placed the geometry into the game but I missed something.
The wheels will not spawn with the vehicle.

I was looking at the "scripted" vehicles. When I click the cheetah or defaultcar, I get the entire geometry with wheels, as expected.

I could use more advice if you could.

#15
01/02/2013 (1:18 pm)
You'll need to execute your ./art/datablocks/cheetah.cs by adding it to ./art/datablocks/datablockExec.cs
#16
01/05/2013 (4:14 pm)
This has been a wild ride, just to get wheels mounted to a vehicle.
There is a long process involved to achieve it and to understand it.
But I now have a scripted vehicle, with the wheels mounted.

Thanks guys for the help.