Problem with different wheels for different vehicles
by SDSC ITEST · in Torque Game Engine · 09/19/2007 (11:56 am) · 4 replies
To reproduce my bug, I'll be using the starter.racing example. I have two vehicles; each with their own unique set of wheels.
In game.cs I create both with:
exec("./car.cs"); //the buggy
exec("./snowmobile.cs");
both have their own separate wheel and vehicle .dts in their appropriate directories.
However, when I run the example BOTH the buggy and snowmobile use the SNOWMOBILE's wheel shape.
When I reverse the "exec" order in game.cs to:
exec("./snowmobile.cs");
exec("./car.cs");
then BOTH have the BUGGY's wheel shape.
Why is this happening? If the object meshes are loading up for each vehicle, why not the wheels as well?
I was going to go through the source code to see if the wheel object is copying each other with each new wheel instance but I figured I'd ask the forums while I'm digging through code. Thanks in advance!
In game.cs I create both with:
exec("./car.cs"); //the buggy
exec("./snowmobile.cs");
both have their own separate wheel and vehicle .dts in their appropriate directories.
However, when I run the example BOTH the buggy and snowmobile use the SNOWMOBILE's wheel shape.
When I reverse the "exec" order in game.cs to:
exec("./snowmobile.cs");
exec("./car.cs");
then BOTH have the BUGGY's wheel shape.
Why is this happening? If the object meshes are loading up for each vehicle, why not the wheels as well?
I was going to go through the source code to see if the wheel object is copying each other with each new wheel instance but I figured I'd ask the forums while I'm digging through code. Thanks in advance!
#2
I have WheeledVehicleTire(BuggyCarTire) and WheeledVehicleTire(SnowMobileTire). However I also have WheeledVehicleData(BuggyCar) and WheeledVehicleData(SnowMobile) which doesn't conflict with each other since their individual .dts files load up correctly... I just thought it would be the same way for their wheel definitions. In WheeledVehicleData I also make sure to make distinct calls in their OnAdd methods to access their corresponding wheel datablocks:
for snowmobile.cs
%obj.setWheelTire(%i,SnowMobileTire);
for buggy.cs
%obj.setWheelTire(%i,BuggyCarTire);
I'm currently going through the wheeledVehicle.cc file to see how the tires load up differently than the actual models. Should I need to edit the source code just to allow different tire meshes? I'm I not thinking of the "easy" way to enable different wheel models?
09/21/2007 (6:03 pm)
Thanks for the speedy response. This is true. I have WheeledVehicleTire(BuggyCarTire) and WheeledVehicleTire(SnowMobileTire). However I also have WheeledVehicleData(BuggyCar) and WheeledVehicleData(SnowMobile) which doesn't conflict with each other since their individual .dts files load up correctly... I just thought it would be the same way for their wheel definitions. In WheeledVehicleData I also make sure to make distinct calls in their OnAdd methods to access their corresponding wheel datablocks:
for snowmobile.cs
%obj.setWheelTire(%i,SnowMobileTire);
for buggy.cs
%obj.setWheelTire(%i,BuggyCarTire);
I'm currently going through the wheeledVehicle.cc file to see how the tires load up differently than the actual models. Should I need to edit the source code just to allow different tire meshes? I'm I not thinking of the "easy" way to enable different wheel models?
#3
09/26/2007 (11:48 am)
Ah I got it. I just needed to define a "className" type within the two .cs files and assign a string for each vehicle. Then in the Wheeledvehicle onAdd function, I just have a small check to see if it's the buggy or snowmobile and loads the corresponding wheels. Thanks!
#4
What I had said one me-post back is that having two datablocks with the same name is one way to get the problem you mentioned. Could happen through cutting and pasting, maybe. The second encountered datablock overrides the first. (This may not be what is causing your problem, based on what you said later.)
You shouldn't need to do anything special to get the correct wheel DTS files loaded. It should happen automatically, and does for me. I am convinced you have a subtle error somewhere that is causing the wrong tires to be loaded. You might put a breakpoint in the WheeledVehicle::unpackUpdate and see what datablock ID it is using on the client. Try it client server and see if it is doing anything different on the remote client and the client-running-with-server. (You might fix it on the client-running-with-server and still have a bug on the remote client.)
09/26/2007 (2:22 pm)
Check this carefully. I believe that OnAdd is only called on either the client or the server. (IIRC it is the server.) I believe the wheels are loaded via the packupdate/unpackupdate methods on the clients (ghost objects). See WheeledVehicle::unpackUpdate. You will see it getting the shape from the datablock. This two methods of initializing Vehicles is a pain. What I had said one me-post back is that having two datablocks with the same name is one way to get the problem you mentioned. Could happen through cutting and pasting, maybe. The second encountered datablock overrides the first. (This may not be what is causing your problem, based on what you said later.)
You shouldn't need to do anything special to get the correct wheel DTS files loaded. It should happen automatically, and does for me. I am convinced you have a subtle error somewhere that is causing the wrong tires to be loaded. You might put a breakpoint in the WheeledVehicle::unpackUpdate and see what datablock ID it is using on the client. Try it client server and see if it is doing anything different on the remote client and the client-running-with-server. (You might fix it on the client-running-with-server and still have a bug on the remote client.)
Torque 3D Owner Matthew Jessick
datablock WheeledVehicleTire(DefaultCarTire)
In this case, the DefaultCarTire datablock would be referenced in one of the fields of
datablock WheeledVehicleData
(Did a quick test and having two definitions of this datablock is indeed one way to cause the problem you mentioned. )