What I am trying to do is find the vector of a object to a point using the position of the object and the position of the player coupled with the rotation of the camera. How would you recommend finding this vector? (I have done this using the player to object vectors length in the vector from camera rotation but this results in the vector I wish to find not being perpendicular to the player to object vector).
I’m not sure how the camera’s rotation plays in to this. What does it matter what the camera’s rotation is if you just want a point perpendicular to the player->object vector? It sounds like it’d be a fixed world position (based on the player and object locations.)
Must the position be the centre of the screen? You want to find the vector offset from the centre screen position, such that it is perpendicular to the player->object vector?
The camera rotation gives the length of the vector I wish to find such that if I press left mouse down on the object and hold, move the mouse above the object and walk around, the vector I wish to find would be perpendicular to the actors position with a length given by the line made using the cameras rotation.
I can post some code I already have if that helps?
FRotator CameraAngle; //Camera Angle Rotator
FVector Player; //Player Postion
FVector Object; //Object Position
FVector DistVector = Object - Player; //Let's get player->object distance vector
//Let's get angle diffrence between camera rotation and distance to object
FRotator AngleDiff = CameraAngle - DistVector.Rotation();
//Let's rotate the distance vector by resulting angle
FVector LookAtVector = DistVector.RotateVector(AngleDiff);
//Based of new vector we can world location of it by adding it back to player location
//Having that let as get distance vector between object->look at point on same distance
FVector ResultVector = Object - (Player + LookAtVector);
You can find the length of the camera vector using acos and the angle (camera->point, actor->object.) I’m assuming the camera is on the player. Or, at least, you are comparing camera->object and camera->point. Once you have the length, you can multiply it by the camera’s rotation vector to get your point. Then use that minus the object’s location to get your vector.
multiply camera->point by the camera’s rotation vector to get the point vector.
Take away the object’s location form point to get your offset vector. If that first line checks out, I’m not sure. It sounds about right, though. Assuming you want something like this: http://puu.sh/md9t6/dc85d99d0e.jpg
Edit: You’ll need to normalise ( object.location - camera.location )
True enough. But, even so, you need some basic understanding of how it all works, even if you can’t remember the specifics, or you’d never know which functions to use!
I have tried the above solution but it did not work, the blue arrow goes in the wrong direction (representing the resulting vector (see picture). Also there is an error with:
As an FVector has no method for RotateVector but a FRotator does so I made it AngleDiff.RotateVector(DistVector), which is what I think you were getting at in the first comment.
I hope I understood your problem correctly. My code will work as long as you’re not looking straight at the object. You can check that the dot product between the camera forward vector and the vector from the player to the object is not zero (greater than 0.0001f would be safer).