Aiming from a pivot

Started by
21 comments, last by Jiia 19 years, 1 month ago
well, if you take my solution and stop at this line:

toTarget.rotateY( -angle );

you can then just do this:

Vector3 aimAtPosition = tankCenter + toTarget;

Aiming at that position will get you the correct orientation if you just pass it to a standard AimAt function. AFAIK this solution will only break down when the target is inside the radius of the circle in your diagrams. remember that the +/- of the angle is determined by whether the turret is on the left/right side of the tank, respectively (again i could have the signs backwards but i think it's right).

-me
Advertisement
Quote:well, if you take my solution and stop at this line:

toTarget.rotateY( -angle );

you can then just do this:

Vector3 aimAtPosition = tankCenter + toTarget;
@Palidine:

Yup, that's exactly what my code ended up looking like. You got it right from the start - it just took me a while to catch up :-)

@Jiia

The error in the perp-vector method is a little hard to describe without a picture, but I'll give it a try:

Imagine (or draw) a tank properly aligned with a target, that is, a line extending forward from the turret crosses the target exactly. Also, draw a line extending along the tank's forward direction vector. The 'adjusted' target position has to lie on this second line in order for the 'aim at' function to work correctly, so that's what we're trying to accomplish.

Now draw a line from the tank center to the target. Next, draw our perp-vector, which starts at the target position, is perpendicular to the tank-to-target line, and has a length of turretOffset.x. You'll see that it doesn't actually reach the 'forward direction line' of the tank. Moreover, the error increases as the turret offset increases.

I don't know if that cleared it up or not (I need to figure out how to post images). Actually, now that I'm thinking about it, it may be possible to use the perp-vector method after all - it's just that the amount of displacement isn't offset.x, but a larger value computed from that. If I figure it out, I'll edit this post with the result.

[Edit]
The good news: you can use the perp-vector method. Bad news: you still have to compute the magic angle! So it's really just two ways of doing the same thing.

If the magic angle is:

magicAngle = pi * 0.5f - acos(turretOffset.x / distToTarget);

Then the amount by which you need to displace along the perp-vector is not turretOffset.x, but rather:

offset = turretOffset.x / cos(magicAngle);
[/Edit]

[Edited by - jyk on March 10, 2005 8:39:38 PM]
But this error, does it only start to go off once the target gets so close? So the angle is irrelevant? And if the target is beyound this certain close distance, there are no problems? If so, then the error distance is probably related to the turret offset and can be used to fix the target further.

Maybe not. I have no idea. Sleep didn't help my brain much.
Anyway, I have 3 different methods to choose from, I don't wanna bug you guys more than that. Thanks for both of your help.

edit: You can upload images to image shack for free. If you mean html-wise, just type in < img src="address" >, with no space after the < , into the post. If that didn't come out right, just view the source code for this page and search for "img",hehe.

This topic is closed to new replies.

Advertisement