Why can't I just get the forward vector of the location?

So I have some code that i was writing from the course of unreal engine and you’re supposed to get location and rotation of the camera view

and then we need to get the end because you do a line trace so you can actually shoot an object or a player but instead of doing this

FVector End = Location + Rotation.Vector() * MaxRange;

can’t we just get the forward vector of the location?

The “forward vector” of the location is the vector from the origin to the location, not the direction you want to shoot.

where would the orgin be and why?

The location says nothing about the direction. A vector can be used for multiple purposes.

Location is saying “At this coordinate X, Y, Z”
Rotation.Vector() is saying "Looking in the direction denoted by X, Y, Z " they would each be a number between -1 and 1, and doing Pythagoras on them would equal 1.

Okay so it’s starting from the camera to where the player shot because its using the rotations vector of the camera so it actually hits the right thing?

Here’s an illustration using 2D vectors. Say the player is (3, 3) from the origin, and looking directly right, so 90 degrees if directly up is 0 and the reach is 5 units.

Rotation.Vector() would turn the FRotator to a unit vector. You can look up the formula for yourself but here you can see that that would be (0, 1) and it’s going directly right. (Note that doesn’t have Roll, as that doesn’t effect direction at all).

If you then multiply that unit vector by Reach you will get a vector that is exactly 5 units in that same direction. If you then add the result of that to Location, you will have a vector that exactly 5 units in the same direction the player is facing.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms