Game Development Community

Trailer implementation

by Nate "Nateholio" Watson · in General Discussion · 02/07/2003 (8:09 am) · 6 replies

Would a trailer be implemented by making a mounting point on the back of a vehicle and connecting the trailer to it? If not how would one do it? Does Torque even have code for using trailers?

#1
02/08/2003 (11:18 am)
hmmm ...
well using the exhisting support for mounting ShapeBase objects.

would give you a Rigid trailer so no .. there is no support.

I dont think the engine is Far from the support needed tho..
hmm.
Interesting issue. I would help with this maybe.
#2
02/08/2003 (1:42 pm)
A rigid trailer would make an interesting but unwanted sight driving around a game world.
#3
02/08/2003 (1:51 pm)
You'd need to make some changes to the rigid body physics to do this the 'right' way, I think. Not as simple as it seems, most likely.
#4
02/08/2003 (1:53 pm)
Well I have no idea how to implement it, I was just wondering if Torque supported it.
#5
02/10/2003 (9:41 am)
Ack. A trailer shouldn't be that hard. I did a similar thing long ago for Q2 (a giant centipede actually). A relalistic trailer behind a vehicle is actually simpler than a centipede action (which required dynamic waypoints).

My Torque code skills are a bit lacking due to unfamiliarity with the current vehicle code, but the basic algorithm is fairly simple:

Create a second vehicle for the trailer. No driver. Determine the point on the driver vehicle (I'll just call it the driver, but it is actually the vehicle) where the hitch is. Same for the trailer (the tongue).

When the positional updates are done, the trailer(s) should not move in it's turn (in case it gets updated before the driver). When the driver is moved, you then trigger the movement of the trailer. Rotate it arount the center point of the trailer until the tongue points directly at the new hitch point, then advance til the tongue and hitch are at the same point. If there are more trailers (road train) update each the same way in order from front to back. Be sure to work the calculations in 3D or it will screw up on slopes.

It gets tougher if you want the trailer to have a pivoting fron axle though (like a farm wagon). In that case, you have to treat the axles of the trailer like separate trailers, where the hitch/tongue point between the front and back is directly over the center of the front axle. Otherwise, the basic idea is the same.



This will create a very poor looking centipede motion, but it will actually look pretty good for a real-world trailer (the farther back along the chain you go, the less the 'wiggles' in the path are followed). That make any sense?
#6
02/10/2003 (10:02 am)
Tim: That'll work in some situations, but it'll fall down if your trailer collided with something that your vehicle didn't hit.

You'd want the trailer to be able to bang to the side when hit, or keep the vehicle from moving forward if it gets blocked.

I'm thinking you'd really want a pair of rigid bodies held together with either a spring or some kind of a hinge constraint.