Game Development Community

How does the car.cs build the buggy properly?

by Smelly McBeard · in Torque 3D Professional · 07/07/2009 (8:39 am) · 30 replies

Hello again guys and gals,

I have a couple questions about the Car.cs file and the buggy inside the T3D engine. Since there is no .cs file other than Car.cs that tells the engine how to build the car (as far as I can tell with my programming knowledge which isn't a lot) I can't understand how the engine is able to determine where to put the tires, how to make the springs work and etc. using a COLLADA file. I understand there is a tutorial for the .dts version of the buggy but I am looking for a way to build a vehicle using a COLLADA file. If anyone could give me a direction to find a tutorial of that sort, or could just give me some information on how to setup a COLLADA file to be used as a vehicle that would be great.

I currently have the COLLADA file with the base of my vehicle in the engine similar to the buggy.dts file that came with the beta. However when I try to add wheels to my vehicle it fails. Thanks for the help folks.

"The Crayfish"
Page «Previous 1 2
#1
07/09/2009 (3:26 pm)
Hi Ryan,

WheeledVehicle models need a node called 'hubX' to indicate where to place each wheel. For example, a four wheeled vehicle would have nodes: hub0, hub1, hub2, hub3. If these are missing, the engine will crash.

Like all 'controllable' objects, the model should also have an 'eye' (1st person camera position) and 'cam' (3rd person camera position) nodes. If these are not present, the model origin will be used instead.

Each wheel should also have an animation sequence called 'springX' used to model suspension. This can be as simple as a 2-frame sequence starting at the fully compressed position, and ending at the fully extended position.

I highly recommend comparing the DTS buggy with your Collada model in the ShapeEditor tool to verify you have the right nodes and sequences before trying to create a WheeledVehicle with it.

The ShapeEditor even has a handy 'Hints' tab that has information about which nodes and sequences are required for a particular type of shape.
#2
07/09/2009 (3:57 pm)
It's the script methods in "server/scripts/car.cs" that mount the wheels, springs, etc when your car is added, look in "art/datablocks/car.cs" for the datablocks to these wheels, springs, etc.

I only mention it because this "script/datablock" split has been a source of confusion to others.
#3
07/10/2009 (7:51 am)
Thanks a bunch Chris and Michael,

Both your answers helped me immensely...but I'm still having issues. The file I made with the new helpers representing Hubs, Cam, eye and springs is still crashing and I just can't figure out why (by the way your suggestion of the hints tab is awesome thank you) but I made hubs for each one of my wheels as well as springs with sequences and in the hints tab under nodes my hub has a red stopX next to it as well as my spring it says X hub0-N and X spring0-N (the X's represent the stop signs) I really appreciate all the help given so far, i'm just trying to understand how to make a Collada wheeled vehicle. Also a little explanation of the Hint's tab would be great, what do the stop signs mean and how do I go about fixing the errors I get in there?
#4
07/10/2009 (7:01 pm)
Hi Ryan,

Does anything of interest show up in the console when the crash occurs? Feel free to send me your car model and I'll have a look at what is going wrong. It sounds like you've done everything right so far.

Quote:Also a little explanation of the Hint's tab would be great, what do the stop signs mean and how do I go about fixing the errors I get in there?

The Hints tab is really just to remind you what nodes and sequences you need to have for a particular type of shape. If you hover the mouse over one of the names it even gives a short description of the item.

When a shape is loaded or edited, any nodes and sequences whose names match those in the Hints list are marked with a green tick.

The red X just means that there is no node or sequence with that name in your shape. I need to make it a bit smarter for nodes and sequences that have a number at the end (eg. hub0-N or mount0-32) since these won't match exactly!
#5
07/14/2009 (5:37 am)
Chris,

I got almost everything working (sorry it's been so long responding) the problem I was having was an error on my end where the wheels that weren't showing up were because my hub's for those wheels were labeled 06-07 instead of 6-7. I am having a couple more issues though, Everytime I load the vehicle model the engine crashes the first time I load it...the second time it will run fine then eventually crash when the vehicle penetrates some geometry. Is this a polycount issue? Or is it an issue in the coding? I know that isn't a lot of information. Also if I wanted to mount a weapon to the vehicle how would I do that? Do I have to create a "mount" node on my vehicle model? Or is there a different way with Collada files? Thanks so much and any help from anyone would be great.
#6
07/14/2009 (2:53 pm)
I'm not sure about the crashing issue. At first I would assume that you were missing a necessary node but since it sometimes works....

To add a weapon to a vehicle you would mount one to a mountpoint just like you would a player.
function AssaultBuggy::onAdd(%this, %obj)
{
   Parent::onAdd(%this, %obj);

   // Setup the car with some tires & springs
   for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--)
   {
      %obj.setWheelTire(%i, AssaultBuggyTire);
      %obj.setWheelSpring(%i, AssaultBuggySpring);
   }

   // Give it some energy so we can use weapons.
   %obj.setRechargeRate(%this.rechargeRate);
   %obj.setEnergyLevel(%this.maxEnergy);
   %obj.mountImage(BuggyBlasterImage, 0);
   %obj.mountImage(BuggyBlaster2Image, 1);

   %obj.setShapeName("Assault Buggy");
}
If your vehicle doesn't have any actual mountpoints you can fake it by using the same mountpoint that the pilot uses (0) and give each weapon image a different offset.

You'll also need a namespace ::onFire() function -- either your vehiclename::onFire() or even shapebase::onFire() would work.

Beta4 will have an example of the GG buggy having two weapons mounted on it that you can fire while driving.
#7
07/14/2009 (3:17 pm)
Can you post what files to change to make the car.cs work
Thanks
#8
07/14/2009 (10:55 pm)
Ryan,

Quote:Everytime I load the vehicle model the engine crashes the first time I load it

Does the engine crash if you just add the model as a TSStatic (using the Library->Meshes tab in the world editor)? Or does it only crash when you add it as a WheeledVehicle?

Quote:Is this a polycount issue? Or is it an issue in the coding?

Hard to say.........roughly how many polygons are in your model? There will be problems if you have more than around 10k in any single mesh.

Quote:Also if I wanted to mount a weapon to the vehicle how would I do that? Do I have to create a "mount" node on my vehicle model? Or is there a different way with Collada files?

As Michael said, you need to create a mountX node (where X is a value from 0 to 32, with no leading zeros!). You can then use the mountImage method to mount a ShapeBaseImage to that node.
#9
07/15/2009 (5:35 am)
Hey guys, thanks for all the help so far. Ok, I managed to get the car into the engine without crashing at all...I don't know why it was doing that. I am now trying my best to mount a weapon and the info you guys have given me is extremely helpful but for some reason it's not working. I have a mount node and I call it out in the code under my car.cs in the scripts folder, i'm just getting the problem of it not working and my vehicles folder just gets deleted so I'm guessing that means I have a coding issue and I am going to have to try to debug it. I'm an artist pretending to be a programmer haha. Thanks for all the help so far and I'm sure I will have more questions soon.
#10
07/15/2009 (10:38 am)
Quote:
and I call it out in the code under my car.cs in the scripts folder, i'm just getting the problem of it not working and my vehicles folder just gets deleted
Whoa, that just blows my mind ;D It deletes your vehicles folder!?

If you want to email me your script I will take a look at it and see if I can spot anything to help you out with that.
#11
07/15/2009 (11:02 am)
I will check if I can do that, I'm working under gov't contract atm so I'll see what's feasible...otherwise I can try my best to explain what is going on but yes, my vehicles folder just disappears.
#12
07/16/2009 (12:08 am)
Quote:i'm just getting the problem of it not working and my vehicles folder just gets deleted so I'm guessing that means I have a coding issue and I am going to have to try to debug it

That definitely should not be happening! Have you made many changes to the T3D source/script base? I can't imagine how this is happening with stock T3D.
#13
07/16/2009 (8:30 am)
Hey guys,

Ok after doing some testing it seems that when I have a copy of car.cs named something different..(i.e. BigVehicle.cs) and it is using the same code that car.cs is but is calling something slightly different however in the engine calling the same vehicle (i.e. DefaultCar) if one of those sources has something incorrect in it, my Vehicles folder disappears from the engine completely. So Messy Code = Messy Results. I have another couple questions though, not pertaining to this topic but i'll post them here anyway, any word on when Beta 4 will be released? And if I package a product and try to play the game on another computer it's missing .dll's for that project but the .dll's are in the folder that is created when I executed the .exe. So I am quite confused. Thanks for all your help so far guys and gals.
#14
07/16/2009 (11:14 am)
Hey guys and gals,

Another question, How is the rocket launcher source file setup does there have to be a mountnode in that file in order for it to be mounted as an image? I'm just trying to figure out how these things work, thanks!
#15
07/16/2009 (4:47 pm)
The mountpoint node is not essential for ShapeBaseImage objects, if it is not present, the model origin will be used.
#16
07/16/2009 (5:11 pm)
Late on answering, but yeah, if there is no mountpoint node then the image usually winds up at "0 0 0" of whatever it is that you're trying to mount to -- but you can use the "offset" field in the image datablock to adjust where it appears at.

Beta 4 should be soon, that's the best I can say... it's up to an employee to say when. In it you will find an assaultbuggy.cs in the FPS kit that has two weapons mounted on it. The example buggy doesn't actually have mount nodes so you'll see an example of how the offset works and a special "trigger" function that alternates between the two mounted guns (left to right) whenever you press "fire".
#17
07/17/2009 (6:15 am)
Nice. I can't wait. I'm having some issues trying to get my weapon to fire right now it says I am out of ammo but I put in a function to make it have infinite ammo, so I don't know. Beta 4 will be awesome, and I can't wait to start disecting the assaultbuggy. Any chance we can get source with the beta release? Thanks.
#18
07/17/2009 (9:04 am)
If you want an early look at the script try thisdownload or thisonline doc. It simply uses the stock buggy and makes use of the steam pistol shape -- so there is really nothing new except for how the scripted functionality is put together. That was a late night when I did that ;D Looking back over it I see places where it could be improved...
#19
07/17/2009 (10:20 am)
@Michael
As an aside, it would appear that you have been inspired by Steve Y's microtext style.
I wish i could be cool...
#20
07/17/2009 (10:54 am)
Oh, I forgot to mention that the assaultbuggy doesn't use ammo -- so it has infinite ammo -- but it does use energy.

@James: lol :D

Come to think of it, I think he was one of the first forum posters I've seen making use of the small text tags. I actually wish these fonts were a bit smaller...
Page «Previous 1 2