# How to decrease the size of a distance?

I made a code for the character to be teleported to the place where the mouse cursor is, if the distance is less than or equal to 350.

Blueprint:

I happen to wish that if the distance were greater, the character teleported to the equivalent point of the line (distance between character and mouse cursor) of 350.

What I would like to know how to do:

I've thought about using the Line Trace by Channel, but I can not think of how to decrease the value of a distance and find the equivalent point in a line (vector value).

EDIT 1 (attempt based in Ocelot comment)

Blueprint:

Result in game:

Now the character teleports to a point that seems to have reference to the center of the level. I tried to add this vector to the character's position, but I did not get the desired result.

PS - The print of the word "Hello" on the screen indicates how many times I clicked on the teleportation key in the last 2 seconds.

"Mouse line up to the mouse cursor" is a vector, and vector could be normalized. Normalized vector is a vector of length 1. What this gives to us is that we can scale it to any length we want.

Simply normalize your character-to-mouse vector and multiply it by your range, that's the solution.

You should do the following steps:

• character position - mouse position
• normalize the result
• normalized value x 350
• character position + normalized value already multiplied

In blueprint (in the case of the question) it looks like this:

• I believe I did what you said, but it did not work out. I edited the question showing what I did. Jun 27, 2019 at 22:41
• @BonecoSinforoso you need to find vector from the character world position to the cursor world position, to do this, subtract character WP from the cursor WP. Then you normalize it, scale, and add to the character position. Jun 28, 2019 at 5:09
• Going a bit further, it will teleport you character exactly to the range point. To make character teleport at any point in the range, you need to check if the length of the vector between character and mouse exceeds your range by taking minimum of the vector length and the desired range, then you should scale teleportation vector by the resulted value. Jun 28, 2019 at 5:15

Not sure about blueprints but this is how i do it.

vector3 GetCoordInFrontOfGameplayCam(float Range)
{
vector3 GameplayCamRot = GET_GAMEPLAY_CAM_ROT(2);//pitch,roll,yaw
vector3 GameplayCamCoord = GET_GAMEPLAY_CAM_COORD();
float Tan = Range * COS(GameplayCamRot.x);
return Vector3(Tan * SIN(-GameplayCamRot.z) + GameplayCamCoord.x, Tan * COS(-GameplayCamRot.z) + GameplayCamCoord.y, Range * SIN(GameplayCamRot.x) + GameplayCamCoord.z);
}

• Thanks for your answer. Would you know how to turn this into a blueprint? My unreal still does not support C ++. Jun 27, 2019 at 21:48