Help with Vector3.Unit Explanation and Examination

  1. What do you want to achieve?
    Nothing difficult, I just want to access a point in between a distance.

  2. What is the issue?
    Apparently, the directional vector of .Unit doesn’t line up? Or i’m misunderstanding how .Unit works.
    image

  3. What solutions have you tried so far?
    Here is my code;

	print((plr.Character.HumanoidRootPart.Position - game.Workspace.Ball.Position).Unit)
	local part = Instance.new("Part", game.Workspace)
	part.Position = (plr.Character.HumanoidRootPart.Position - game.Workspace.Ball.Position).Unit
	part.Anchored = true

According to several topics and post that I have read, .Unit is by default 1 unit to the direction of a Vector3.
image
For some reason, the part instanced is not in either the red or blue circle. But is under the green arrow.

If there are any misunderstandings, just ask me and I’ll clear them up!
Anything Helps!

1 Like

A unit vector is a vector who’s magnitude is 1
Its often used to describe direction

That is correct. But the part was not instanced where I believe it should be.

I don’t think you are quite understanding what a directional Vector is used for. It is meant to indicate a certain direction as a Vector3, not a position.

Here is a post I made a while back explaining this that might help:

If you set the .Position of a part to a directional Vector, it will interpret it as a position in 3d space, not the direction like you want.

Try adding the .Unit Vector to the .Position of the character’s HumanoidRootPart. This should make the position line up.

part.Position = plr.Character.HumanoidRootPart.Position + (plr.Character.HumanoidRootPart.Position - game.Workspace.Ball.Position).Unit * ExtendDistance

I’ve read this topic, twice. I respect the question and I see the response. But if Vector3.Unit is not the way to go, what is? Magnitude returns a single number, not a Vector3. I’ve considered maybe raycasting but it seems overly complex for something that may have a simple solution.

If you want a point between some distance, try using this simple method

local randompos = (pos1 - pos2).magnitude / somerandomnumber
local vectorToRandomPos = (pos1 - pos2).unit * randompos
1 Like

I’ve tried this already, but I removed it from the code above. That did not produce good results.

This code should plot the Part in between the character and the ball:

part.Position = plr.Character.HumanoidRootPart.Position + (plr.Character.HumanoidRootPart.Position - game.Workspace.Ball.Position).Unit * ((plr.Character.HumanoidRootPart.Position - game.Workspace.Ball.Position).Magnitude * 0.5)

image

Just make sure you offset it by pos1, so…

local vectorToRandompos = pos1.Position + (pos1 - pos2).unit * randompos
1 Like

Ah! Alas, something I did not try. Thank you!

Will give it a test.

EDIT: I just realised it is the same as @ExcessEnergy 's code.

You can alternatively use Lerping, which might be a simpler solution in his case.


part.Position = plr.Character.HumanoidRootPart.Position:Lerp(game.Workspace.Ball.Position, .5)

The .5 you see is a decimal representing the in between point. 0 equals the start point, 0.5 equals the middle, 0.75 equals three fourths the way, ect.

1 Like

I didn’t consider lerping as a use case for this. Thank you!

Your essentially doing the same thing lol