TenOunce
(TenOunce)
September 4, 2020, 3:01am
#1
What do you want to achieve?
Nothing difficult, I just want to access a point in between a distance.
What is the issue?
Apparently, the directional vector of .Unit doesn’t line up? Or i’m misunderstanding how .Unit works.
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.
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
TenOunce
(TenOunce)
September 4, 2020, 3:04am
#3
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:
A Unit Vector is a Vector who’s values are based on 1. This is basically only used for directional vectors as far as I know.
The main use of this for me personally, is to condense the values down, so that you have a directional Vector that can be extended out a desired distance, while still maintaining the direction aspect.
For example:
BasePartPosition = workspace.BasePart.Position
LookAtPartPosition = workspace.LookAtPart.Position
Direction = LookAtPartPosition - BasePartPosition --right n…
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
TenOunce
(TenOunce)
September 4, 2020, 3:07am
#5
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
TenOunce
(TenOunce)
September 4, 2020, 3:11am
#7
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)
Xx1Luffy1xX
(Xx1Luffy1xX)
September 4, 2020, 3:12am
#10
Just make sure you offset it by pos1, so…
local vectorToRandompos = pos1.Position + (pos1 - pos2).unit * randompos
1 Like
TenOunce
(TenOunce)
September 4, 2020, 3:13am
#11
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
TenOunce
(TenOunce)
September 4, 2020, 3:17am
#13
I didn’t consider lerping as a use case for this. Thank you!
Xx1Luffy1xX
(Xx1Luffy1xX)
September 4, 2020, 3:18am
#14
Your essentially doing the same thing lol