Game Development Community

Wheel vehicle Trailer?

by Anthony Rosenbaum · in Torque Game Engine · 02/20/2003 (10:04 am) · 13 replies

With the new wheeled vehicle code allowing the designer to have the wheels be controlled by the engine or not. How hard would it be to alter the exisiting class or create a new one that can be towed behind like a trailer.

#1
02/25/2004 (12:44 pm)
Hey anthony. are you still working on this problem? I am just now attempting to find a solution. I too would like to create a truck with a trailer. Please let me know if you ever got it to work.

Thanks
#2
02/25/2004 (6:27 pm)
Haven't worked on it perse but would love to help anyway I could
#3
02/28/2004 (8:50 am)
Thank you Anthony! I'm pleased to have recieved a reply so soon.

I have looked at the source code for mounting objects in ShapeBase.cc, I've also looked extensively at the code for Wheeled Vehicles. I have a few ideas of ways I might tackle the problem of creating a trailer for a truck.

1. try using two vehicles and mounting one to the other at a mounting point set where the hitch would be.

2. Make the trailer and truck one model and create animation sequences for the trailer movement, then call the correct sequence based on steering and the degree of spring extension for each wheel. (this would allow the trailer to move on sort of universal joint. I want it to react to terrain separately from the truck)

3. Or, use two vehicles, and whenever the player vehicle moves I could make the trailer move apropriately so that it is constantly connected to a hitch or joint.

To do this I would have to rotate the trailer to point towards the hitch (mounting point) then close the gap between the trailer and truck. I could use two points: the pivot of the trailer and the mounting point on the truck. Subtract the mounting point from the pivot point giving me a vector with both direction and distance. I could then add this vector to the pivot point effectively keeping the trailer connected.

Anyway, at first glance do these seem like viable options?

Of course your original post about modifying the existing class to create a trailer class sounds like the best way to go! Please let me know what you think, and maybe we could figure this thing out together.
#4
02/29/2004 (3:38 pm)
ACtually if you notice the current wheel vehicle has tons of neat options like turning off engine/steering influence per each wheel, so you can have 2/4/6/x wheel steering and wheel drive types.

I thought of modifing the class to have an "isTrailer" variable and a setTractor(%wheeledVehicle) to inherit the forces from the pulling vehicle. Im rather rusty ing physics so I'm not sure how to caluclate the delay. essentially your number one.

Problem with number two is that is would actually be one vehicle and if you want to drop the trailer off (as I have plans for) it wouldn't work without "faking it" (changeing models on the fly and generating a new model for the trailor) which I rather not.
#5
03/01/2004 (6:22 am)
Anthony, I have looked at the Open Dynamics Engine (ODE), and apperently there are some people trying to integrate it into Torque. Hopefully this will happen soon. If not I might try giving it a shot. This would give us exactly what we need to do some real rigid body physics with an articulated truck. But, the biggest problems seem to be with using it for client/server applications.

I think your idea would be a good solution. But, it will certainly take some brain power. For now I think I will try to make a hinge class. This will allow me to connect two wheeled vehicles together. I will first experiment with just getting one wheeled vehicle to follow the player's vehicle. Then I'll move it in closer, so that it is connected like a trailer should be. This won't take care of the true physics of joined rigid bodies, but it's a start. And it would also then be a simple task to disconnect the trailer.

Thanks again for your help. I'll let you know what I figure out.
#6
06/28/2004 (12:57 pm)
Ryan I just recently got wrote the code to connect 2 wheeled vehicles, As you surmised the steering need to be more "hinge" like. Have you had any sucess in your attempts?

Does anyone know a good site where I can get trailor physics explained?
#7
04/16/2005 (3:46 pm)
Has there been any progress to this? I would like to get a tractor / trailer in-game and I'm not quite sure where to start.

I was thinking that two vehicles with a mount point on each would be the best way to do it, but I'm unsure how to apply the force of one vehicle to that of another.
#8
04/17/2005 (5:11 am)
To get the tractor to pull a trailor all you have to do is use another wheeled vehicle's id. As for correct propulsion, and more importantly useing a joint for the hitch, for correct steering. Well my math skills are not up to the task. If you ARE capable of such a task I might be willing to share.
#9
07/01/2005 (1:32 pm)
Is there a way to get the two front hub nodes to animate with the front of a truck as it turns "left" and "right"? Thats the problem I'm having as I can't get the hubs position to be animated with the turn sequences. The hubs just stay in place when I'm driving my truck in game.
#10
07/02/2005 (10:41 am)
When you animate the hub nodes, you aren't necessarily animating the wheel position. When a wheeled vehicle object is created, each wheel is placed relative to a hub node. Normally, the positions of the wheels don't change - other than their up/down motion on the springs.

To get the wheels to move along with your hubs you would have to determine the hubs location every frame and update the position of each wheel. This would probably be done in WheeledVehicle::advanceTime, where the angular position is being updated for each wheel.

Also, take a look at WheeledVehicleData::preload to see how to read the position of a hub node. Are the wheels still going to steer on their hub axes, or are they going to remain straight and perform "toy car" steering? You have to be careful when changing the wheel position because the driving physics will be effected.

Just a quick note; when we were asking about this stuff we were in the middle of our own game, and we were racking our brains trying to get this moving trailer effect. We've since finished this project, and we ended up simply adding an animation where the back trailer moved from side to side. We tied the animation to the players steering, so it looked as if the back was swaying when the player turned from side to side. The animation is just a subtle movement, but it looked real good.

Sometimes "faking it" is the way to go. Don't get caught up on trying to mimic reality to a T.
#11
07/02/2005 (2:15 pm)
Thanks for your feedback, thats what I'm kind of doin here, although I made the front of the truck part of my " turning " sequence. So the hubs position can't be animated then, is that what I'm gathering?
#12
12/03/2005 (2:39 pm)
Old thread I see. I need to do something similar to this.

I have a wheeledvehicle that needs to mount to another wheeled vehicle which can then also be mounted to another wheeled vehicle. Sort of like a train, however, it the newly mounted ones physics do not have to act like that of a train or a trailer, just as long as they are attached to the original is fine.