How to get the position of the front side of a part

Hello so I have a part and I want to teleport the player position of the front side of the part

here is some images describing what I mean:
image
image
image

where the red brick represents the front of the front and even when the part is rotated the “front” position remains

2 Likes

You could use LookVector or, even simpler, position the player a set amount of studs away from part’s Z-axis position.

local cf = part.CFrame * CFrame.new(0,0,-5) -- exactly 5 studs from center
3 Likes

I am pretty sure when I rotate the part the orientation changes but the CFrame stays the same. So if I do -5 on the Z-axis, it wont put it in front

1 Like

When you Apply a CFrame Position with a Rotation, it should go based on the Rotation as well.

CFrame is both Position and Orientation

2 Likes

To get the position exactly in front of the part, you can use the following:

local frontPosition = Part.CFrame.LookVector * Part.Size.Z / 2
1 Like

okay so I lied about my issue what i am actually trying to do is make a jumpscare and I need to get the position in front of the monster to tween the camera to

Here is what I did based on what you said which seems to work

	local tween = game:GetService('TweenService'):Create(workspace.CurrentCamera, TweenInfo.new(1), {
		CFrame = monster:GetPivot() * CFrame.new(0,0,-5)
	})
	tween:Play()

the only issue is that its facing the same direction the monster is facing. I want it to be facing toward the monster

the reason I lied about the issue is because the solution for both things is practically the same and Its just so much easier to make a post and to convey what I am trying to do

this is a video showing what the jumpscare is right now

You can try replacing the above code with the following:

local tween = game:GetService('TweenService'):Create(workspace.CurrentCamera, TweenInfo.new(1), {
    CFrame = CFrame.lookAt(monster:GetPivot().Position + monster:GetPivot().LookVector * 5, monster:GetPivot().Position)
})
tween:Play()

EDIT: Modified from LookPosition to LookVector, I made a typo!

2 Likes

It works but its not the best. There are so many issues with the jumpscare and its really annoying since I have been working on it for the past 4 hours

1 issue is that its not consistent with the position when I tween the camera. Sometimes its too high and sometimes its too low but I want it to be professional and perfect.

2nd issue is that the monster keeps falling over even though it doesnt collide with the player and I dont know how to get it to stop

3rd issue is the monster has to completely walk inside of the player sometimes even though my script checks if the monster is 15 studs away.

I do not know why there are so many issues and I havent been able to solve any of them regardless of the amount of work I have put in

Here is a video which shows you:

See how its so unproessional and chaotic. I dont know how to fix it!!!

The issues you are mentioning are unrelated to the post’s title " How to get the position of the front side of a part". What I provided above is the answer exactly to your initial post’s title and description, but now you seem to be asking about way more things, and I doubt anyone can answer all of these with so little context.

It would be too much to write code to fix all of these, but here are some tips I would give you:

This is because you tween to the initial monster’s position. However your monster seems to be moving even after the Tween is created. If your monster moves a little higher or lower, then the initial point you started tweening the camera to, is not the correct one anymore. It seems like you want more of a Camera Focus/Following system, rather than a Tween.

How do you control your monster’s movement? If you are using body movers, make sure to read on AlignOrientation.

Here there are many moving parts that could go wrong. How often are you checking for the distance between the monster and player? How do you actually make this check? Are your scripts local side or server side?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.