Sign in to follow this  
Eldritch

Minimap and arrow pointing in objective direction (solved)

Recommended Posts

I am trying to implement a minimap into my game, and I wanted to put an arrow in the outer circle of the minimap (it's a circular minimap, much like the one seen in GTA, except that it rotates when the player rotates rather than the "player representation" on the minimap rotating, there is a reason for this). The problem I am having is finding a suitable calculation for doing so the arrow is pointing in the correct direction of the mission objective. I tried to use vector projection (i.e. angle = acos((DotProduct(PlayerToObjectiveVector, PlayerFacingDirectionVector))/(VectorLength(PlayerToObjectiveVector)*VectorLength(PlayerFacingDirectionVector))), but it did not work as I had hoped. I also tried calculating some triangle stuff, but that was even worse. Anyone got any useful suggestions? [Edited by - Eldritch on June 30, 2005 11:49:41 AM]

Share this post


Link to post
Share on other sites
First of all, here's an alternate way of finding the signed angle between two 2d vectors that may be of use to you:

angle = atan2(a.PerpDot(b), a.Dot(b));

The input vectors needn't be unit-length, and you avoid the stability problems of acos(). Your game may be 3d, but often AI and that sort of thing can be reduced to a 2d problem. I don't know whether that's the case for you. (There's a similar function for 3d if you need it.) In any case, it should be no trouble to get the relative angle between the target and forward vector, and convert this to an arrow on your minimap. Perhaps you could post the code you have currently, and explain exactly how it's not working.

Share this post


Link to post
Share on other sites
Hmm, never realized there was another atan2 function... With big risk of sounding like a stupid person I have to ask... in your example, what is "a" and what is "b"? Are the PerpDot and Dot functions something included in the C++ standard library? I became a little confused :)

I am doing this in 2D to calculate the angle between the vector that points in the direction the player is facing and the vector from the player to the mission objective, since I want an arrow to rotate around my minimap to point in the direction of the mission objective.

My two 2D-vectors are PC.missionTarget and PC.position.

I cannot display any code since I don't have any for this... I dunno what to write, hence why I made this post :)

Share this post


Link to post
Share on other sites
'a' and 'b' are any two vectors. In your example they would be 'PlayerToObjectiveVector' and 'PlayerFacingDirectionVector'. Dot() and PerpDot() are functions that you will have to write. Dot() is just 'DotProduct()' from your original post, but just in case:

a.Dot(b) = a.x*b.x+a.y*b.y

PerpDot():

a.PerpDot(b) = a.x*b.y-a.y*b.x

If you implement this and the arrow is still in the wrong place, it may be because you have a different convention for rotation direction or which direction is forward when there is no rotation. You can always fix this sort of problem through some combination of adding a multiple of 90 degrees (PI/2) to the result, negating the result, or swapping and/or negating the arguments to atan2().

Let me know if you have any other questions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this