Jump to content
  • Advertisement
Sign in to follow this  

Trailer object implementation

This topic is 4492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have been trying for weeks spread over like a year, to get the following working: I have an object (horse) which has a trailer object (wagon/cart). I cannot get this to work. I have tried everything that I could think of: - Used the physics engine that I use, ODE. Unfortunately, it just does not work out well, it's very tricky to model. I've tried using joints, using contacts and low friction, etc. - Splines. I keep 10 points of the horse object, and make the other object follow this spline. It looks a lot better already than ODE did for me, but it's quite tricky to get the timing offset in the spline right, it seems to jump a bit. Right now I'm sure there should be a reasonable simple standard way of doing this. Unfortunately, my math skills aren't exactly the best. The gamedev search only leads me to trailers as in previes (of games or movies), and not the trailer kind I want ;). Next to that, I'm not even sure if "trailer" is a good keyword to search on. Can someone maybe shed some light on this problem? I have tried my best, but somehow, it just doesn't work out :(.

Share this post

Link to post
Share on other sites

I have the object on the appropriate "anchor" now. Still, I can't get the rotation to be updated like it should:

I have tried:

- Interpolating rotation matrices
- Interpolating quaternions fetched from the matrices
- Getting the angle between connection points
- Getting a lookat matrix for the two objects
- Turning the direction (truck-trailer).normalize in a matrix

etc. Nothing helps. All I need now is to get the appropriate rotation.

I have the following:

- Position of truck and trailer
- Position of truck and trailer connector points
- Rotation matrices of truck and trailer.

(where truck and trailer are horse and wagon :P)

I'm sure this is a piece of cake for anyone who has a bit of math background.. :)

Share this post

Link to post
Share on other sites
I have no solution yet, but a question:

Are you speaking of a one fixed axis wagon like a roman fight wagon (don't know whether it is actually named so in english) where the wagon's heading is done only by wheel rotation, or do you speak of a two axes wagon where the rear axis is fixed but the front axis has the freedom of heading (i.e. rotation around vertical axis) into the direction the horse is pulling the vehicle?

[Edited by - haegarr on April 4, 2006 5:49:04 AM]

Share this post

Link to post
Share on other sites
Image Hosted by ImageShack.us
Hmmm... that image was supposed to have a white background... I hope you'll bear with me...
To get the new angle / heading (the direction the trailer faces), take

angle = angle + math.atan2(normal dot ownerDeltapos, distance)

You can find the normal from the angle. It is possible to integrate in the tangential direction as well to get the movement of the trailer, but it will suffer from numerical inaccuracies (I presume you want the distance between the vehicle and the trailer to be fairly constant), and I think it's unnecessarily complicated.
Once you find how the angle changes, simply step (distance) units in the (angle) direction and draw the trailer there

Share this post

Link to post
Share on other sites
Hi, thanks! I'll give it a try.


Like these: :)


Share this post

Link to post
Share on other sites
I think I would simulate the horse/wagon situation as follows:

From the photos linked above the model is a two axes wagon, where the rear axis is fixed and the front axis is steerable. The steering is done by a bar. On the other end of the bar the horse is pulling. The bar is always (more or less) parallel to the horse's body axis, and hence IMHO the situation differs slightly from a tractor/trailer situation as depicted above, since the tractor/trailer situation shows 2 hinges but the horse/wagon situation only 1.

Let us denote the hinge located in the center of the steerable axis as point A. Let us furthur denote the center of the fixed axis as point B. If is clear that at any point of time the length
l := |B - A| = const
or else the wagon would break into pieces if pulled away.

Now, assume the horse pulls point A a distance d given by the current movement direction and the time elapsed since the last simulation step. As a result the position
A' := A + d
is reached. The orientation of the steerable wagon axis is always perpendicular to the bar and hence to the direction of pull. The position B would remain where it is but must follow the above constraint. In fact it is pulled towards A'. I suggest to model this by computing the difference
b := B - A'
from the new point A' to the former point B, and from that a ray
R(n) := A' + n * b / |b|
and locating the new point
B' := R(l)
with l being the length of the wagon as defined above.

This method computes an asymptotic approximation of the path of B to the path of A, even if the horse changes its speed or direction of movement at any time (also going backwards will work in principle).

So you have the updated A' and B', you have an implicit given orientation of the steerable axis, and from A', B' a wagon orientation could be computed by trigonometrics if needed. From the given data also the wheel rotation could be computed (in combination with the width of the wagon also the differences of the inner and outer wheel rotations are computable, but I think that would be exeggarated).

I haven't implemented the method above, it is full theoretical until now. It is, of course, a discrete time step simulation of the (expected) real behaviour.

[Edited by - haegarr on April 6, 2006 3:36:50 AM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!