Calculate Front Of Part Position

  1. What do you want to achieve?
    I need to calculate where is the front of a part (position).
  2. What is the issue?
    The Position property is in the middle not at the front of the part.
  3. 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.

local Front = Part.Position + Vector3.new(Part.Position.X / 2, 0, 0)
1 Like

I tried that, but the part is way off.

wdym? can you provide a screenshot?

Blue is where is it suppose to be. Red is what the part did.

MyPartIsBuiltDifferent

what is the name of the part you want to get the front of

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

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

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.

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)

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)

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

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?