OwlCodes
(Owl)
October 1, 2022, 10:59pm
#1
What do you want to achieve?
I need to calculate where is the front of a part (position).
What is the issue?
The Position property is in the middle not at the front of the part.
What solutions have you tried so far?
I have tried some math, but I am not really good with it.
The Part Position is in the middle, but I need the front of the part’s Position!
local Part = Instance.new("Part")
Part.Name = "TestPart"
Part.Parent = workspace
Part.Size = Vector3.new(1,1,1)
Part.CFrame = CFrame.new(script.Parent.IKPart1.Position, script.Parent.GrabPart.Position)
Part.Anchored = true
Part.Color = Color3.fromRGB(255,0,0)
Part.Transparency = 0.5
This is probably some math, but I am not good with math.
vParkuu
(_)
October 1, 2022, 11:00pm
#2
local Front = Part.Position + Vector3.new(Part.Position.X / 2, 0, 0)
1 Like
OwlCodes
(Owl)
October 1, 2022, 11:02pm
#3
I tried that, but the part is way off.
vParkuu
(_)
October 1, 2022, 11:03pm
#4
wdym? can you provide a screenshot?
vParkuu
(_)
October 1, 2022, 11:06pm
#6
what is the name of the part you want to get the front of
OwlCodes
(Owl)
October 1, 2022, 11:07pm
#7
It’s called IKPart1. This is what I did:
The Part being made is the Red Part.
local Part = Instance.new("Part")
Part.Name = "TestPart"
Part.Parent = workspace
Part.Size = Vector3.new(1,1,1)
Part.Position = script.Parent.IKPart1.Position + Vector3.new(script.Parent.IKPart1.Position.X / 2, 0, 0)
Part.Anchored = true
Part.Color = Color3.fromRGB(255,0,0)
Part.Transparency = 0.5
RefusalMan
(RefusalMan)
October 1, 2022, 11:08pm
#8
In case it’s oriented, you can just use the LookVector
local position = part.Position + part.CFrame.LookVector*5 --note that it will get the position of 5 studs in front of the part. You can just remove the '*5' part and leave nothing, and it'll return the position of one stud in front of the part's LookVector
1 Like
OwlCodes
(Owl)
October 1, 2022, 11:10pm
#9
This seemed to work, but what if the parts are different sizes? How could I make sure that it goes exactly to the front?
Also, thank you.
vParkuu
(_)
October 1, 2022, 11:14pm
#10
My previous solution didnt worked bc i accidentally changed size to position when dividing by 2.
Using rubixxman solution’s it will look like that
local Front = script.Parent.IKPart1.CFrame.LookVector * (script.Parent.IKPart1.Size.X / 2)
OwlCodes
(Owl)
October 1, 2022, 11:17pm
#11
My X is 1, so doing that only moves it 0.5.
um just wondering why all of you are using the x axis but assuming you want the front of the z axis:
local Front = Part.CFrame.LookVector * (Part.Size.Z / 2)
vParkuu
(_)
October 1, 2022, 11:20pm
#13
yea, it gets the position that the part ends
use this instead:
local Front = script.Parent.IKPart1.CFrame.LookVector * ((script.Parent.IKPart1.Size.X / 2) + Part.Size.X / 2)
local frontpos = script.Parent.IKPart1.CFrame.LookVector * script.Parent.IKPart1.Size.X/2
works for me
vParkuu
(_)
October 1, 2022, 11:25pm
#15
Actually, this is the correct script:
local Front = script.Parent.IKPart1.CFrame.LookVector * (Part.Size.X / 2)
How would I make it so it looks at the top of the part and not the front?