Vector Math Problems

Hey Guys,
I actually want to solve a simple problem, but after a week of trying everything I just couldn’t manage to have it behave correctly:

For my game there should be some kind of “aim bot” ability/spell. The horizontal aiming works fine by using setViewDirection for the BetterCharacterControl, however the pitch is a bit problematic for me:

I do NOT want to use camera.lookAt() but rather find out the pitch angle to fake player input, but here comes the problem:

Theoretically all I have to do is use the dot product between the target vector and the “neutral” position (which is the direction into the cam looks when the player induced offset is 0f).

This works to some extend (The more your cursor deviates from the target, the worse the angle will be off).
The Problem for this is: The Camera Position is calculated roughly like: Player Position + rotated camera offset. What happens is: As you change the pitch, the camera position moves, invalidating the angle. When you are already aiming perfectly, the camera position doesn’t change, hence the angle is correct.

Do you have any tips or completely different approaches which I am overseeing? I even wrote 1 Page of LaTeX Formulas already just to end up being more confused than before :smiley:

I’m still not understanding why turning based on two dot products is not enough.

Vector3f relEnemyPos = enemyWorldPos.subtract(botWorldPos);
Vector3f botLeft = botWorldRot.mult(Vector3f.UNIT_X);
Vector3f botUp = botWorldRot.mult(Vector3f.UNIT_Y);

float turnLeft = botLeft.dot(relEnemyPos);
float turnUp = botUp.dot(relEnemyPos);

Then turn yaw based on turnLeft * rotationSpeed and turn pitch based on turnUp * rotationSpeed.

If there is some reason that doesn’t work then I think it just means you are using the wrong positions.

1 Like