# Math Problem

I have two vectors:

• One is a direction (the current agent direction)
• One is the goal (a point)

I want to steer left or right, depending on wich one of them has the lowest angle between it and the goal.

So, here’s what I’m doing:

[java]

Vector3f steer = direction.cross(Vector3f.UNIT_Y).normalize();

if (steer.angleBetween(goal.normalize()) < steer.negate().angleBetween(goal.normalize())) {

return steer;

else

return steer.negate();

[/java]

Can someone help me understand why is this wrong?

Edit:

Does the current location of the agent (the one who has a direction) matters here? (I think not, as the angles shouldn’t change)

You want to compare the angle between the direction and the normalized goal, not the steer. Note that this will make it wiggle back and forth, you will want to clamp it, or at least scale the steer value based on the distance needed to turn.

@Sploreg

I’m so dumb, thank you for correcting me. Now I’ve create other problems, but I’m dealing them one at a time. Your AI library is being expanded, in time it will be ready to be used for other users. First things first, let’s make it usuable first ^^

Math is hard, ur not dumb You can always draw the direction vectors, as I did, to help debug what is pointing where.

Good to hear you are working on the AI library. It could become quite useful I think.

@Sploreg said:

I did draw the vectors, and for somereason it wasn’t working. I could swear this could be achieved with the steer vectors, since they are a rotation around the Y axis about 90 degrees left or right. But using the direction, I’m able to do the same thing, just need a different condition afterwars.