[MATH] Why do I need to add player location to the rotation vector if the start point is already the location?

Hi,

So I’m a math idiot and what flies completely over my head is the sequence of operations that we’re to perform in order for the DrawDebugLine to work properly.

My reasoning is such: since DrawDebugLine takes PlayerViewPointLocation as the starting point, why do we have to include PlayerViewPointLocation as a value for calculating LineTraceEnd?

I thought that for the calculation of LineTraceEnd all you need is playerViewPointRotator.Vector()*Reach, but obviously this doesn’t work. Not only does it not work, it doesn’t work in a surprising way, since if you calculate it like this the line will be static. It will draw the line using the starting player rotation and never update the line despite being a tick component and despite player rotation changing. Is there any chance I could get an ELI5 on why does it behave like this?

1 Like

I myself haven’t updated my vectors in a while but I can explain why I think we did that.

In games, all points are referenced off the origin, so a whole map will have a single origin and all the objects would calculate their position relative to the said origin.

Thus the location of the pawn is stored in a vector [direction (in which direction from the origin, the pawn is) + magnitude (how far in the said direction the pawn is from the origin)]. So, the “PlayerViewPointLocation” is the direction + distance from the origin (0,0,0).

Now, we need to calculate the direction in which the pawn is looking. Lets say it is stored in vector A. But a vector which has 0 magnitude is called A ‘cap’. The ‘cap’ signifies magnitude is 0 iirc. Thus we multiply the ‘reach’ to this A cap to give it a magnitude turning it into vector A.

Now we have two vectors, the position vector of the pawn which tells where the pawn is in reference to the origin, and the vector A which tells the end position of the line trace (the direction and distance).

Now you might be wondering why not just use vector A and why did we add PlayerViewPointLocation?

When we add the two vectors, we get the endpoint of the trace RELATIVE to the origin.

This will clear the concept of why we added vectors.

Please, if I am incorrect feel free to correct me, as I also thought of the explanation just after I watched this video.

1 Like

Privacy & Terms