Vectors: How would I keep an object in front of the character during play?

I’m following a tutorial on YouTube to create a vertical sphere trace that should stay in front of the character, per part of the tutorial at the bottom of this post.

Now, I have gone over everything and triple-checked my code. It matches his exactly. For some reason, it is always staying a few units further than the character on the X axis.

Now, I am trying to re-think the code, and make it work for me. I’ve gone through a couple of YouTube videos explaining the basics of Vectors, but none have really explained how to combine/add/multiply them. Even one titled “Vector math”.

So, I’m attempting to get the player’s location for the Z axis value, then add it to the player’s forward vector (X and Y axis values) to get the direction that the sphere trace should be from the character. Adding these should put the sphere trace in front of the character, and at it’s Z height, right?

This is my code:

And this is what it looks like in the player:

UPDATE

I copied the code from the forward vector and have been messing around with it. Now it seems to be staying in front of the character.

Would anyone be able to explain why this math is the way it is, or point me to a resource that will help me better understand the concept?

Hey there @ImKim! So you did everything right but changing the data type.

So the green pins are floats, what you did with the plus node (red box) was add the player’s Z height, with the forward vector’s X + 50 and y + 50. This results in a single float being passed into a vector. So essentially you just added these floats together to one single number, and changed it to a vector. Basically (example number) 50+51+51 = 152 → Vector (x 152,y 152,z 152) isn’t going to output a proper Vector.

Now take a look at your correct solution, it’s pins are yellow, which means it’s inputting and outputting a Vector. So instead of trying to add the floats together, you’re assigning the variables to the correct X, Y, and Z in the vector, but that’s handled natively by the data structure. Adding Actor location to a multiplied Actor forward vector effectively does this X+X,Y+Y,Z+Z.

Does that clear it up?

It does! Thank you