How to position a part a bit in frount of where the player is looking

I want it so that when I press something it positions the part 5 studs away from them in the direction that they are looking I already have the press event I just don’t know how to do that.

Try this.

local p = Instance.new("Part",workspace)
p.Position = (game.Players[SomePlayer].Character.HumanoidRootPart*CFrame.new(0,0,-6)).p

You can use .LookVector to get the position in front of where a part is face,
And then times it for the distance you want in front (in this case 5)

part.Position = character.HumanoidRootPart.CFrame.LookVector * 5
1 Like

Here is my code for it but this happens

image

	E1Clone:SetAttribute("Owner", player.Name)
	E1Clone.Parent = workspace
	E2Clone.Parent = workspace
	E3Clone.Parent = workspace
	E4Clone.Parent = workspace
	E1Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E2Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E3Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E4Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E1Clone.Position = HumanoidRP.CFrame.LookVector * 5
	E2Clone.Position = HumanoidRP.CFrame.LookVector * 5
	E3Clone.Position = HumanoidRP.CFrame.LookVector * 5
	E4Clone.Position = HumanoidRP.CFrame.LookVector * 5

It does not go where I look

Maybe reverse them?

- (hrp.CFrame.LookVector*5)

I don’t think I’m doing it right its not working

	E1Clone.Position = - (HumanoidRP.CFrame.LookVector*5)
	E2Clone.Position = - (HumanoidRP.CFrame.LookVector*5)
	E3Clone.Position = - (HumanoidRP.CFrame.LookVector*5)
	E4Clone.Position = - (HumanoidRP.CFrame.LookVector*5)
	E1Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E2Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E3Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)
	E4Clone.CFrame = HumanoidRP.CFrame * CFrame.Angles(0, math.rad(90), 0)

Oh your reseting the position of the clones each time.

local cframe = CFrame.new(HumanoidRP.CFrame.LookVector*5) * CFrame.Angles(0, math.rad(90), 0)

E1Clone.CFrame = cframe
E2Clone.CFrame = cframe
E3Clone.CFrame = cframe
E4Clone.CFrame = cframe


they all kinda spawn in the middle

The problem here is lookVector returns the front direction of the part. It is relative to the part so you must do


E1Clone.Position = HumanoidRP.CFrame.LookVector * 5 + E1Clone.Position 
-- Adds the lookVector to the current position
--Before you were positioning it in world space

It now spawns them really far away

Code:

	E1Clone.Position = HumanoidRP.CFrame.LookVector * 5 + E1Clone.Position 
	E2Clone.Position = HumanoidRP.CFrame.LookVector * 5 + E2Clone.Position 
	E3Clone.Position = HumanoidRP.CFrame.LookVector * 5 + E3Clone.Position 
	E4Clone.Position = HumanoidRP.CFrame.LookVector * 5 + E4Clone.Position 

Must be

E1Clone.Position = HumanoidRP.CFrame.LookVector * 5 + HumanoidRP.Position

image
You are getting the lookvector and add it to the position of the part.

image
If you don’t add the position, it put is in world space

That works but how do I also make it orientate so it is facing me

Got to go after this post. Other devs can help you if you run into anymore problems.

Use CFrames to rotate and set the position

Change it to:
E1Clone.CFrame = CFrame.new(HumanoidRP.CFrame.LookVector * 5 + HumanoidRP.Position, HumanoidRP.Position)

I was rushing this but that should work. Sorry but I don’t have time to explain what I did.

gl

3 Likes

It works but its just rotated the wrong way tysm

Yeah you can probably just rotate to your liking! :ok_hand:

1 Like

Sorry to bother you again and your probably gone now but for the life of me I don’t know how I would rotate to my liking.

Well, I’m not exactly sure that this is the most effective way, but you can do:

E1Clone.Orientation += Vector3.new(0, 90,0)
1 Like

Thanks this worked I could just no figure it out

You could just rotate the instance which is being cloned -90 degrees or 90 degrees around the Y-axis such that its clones are correctly oriented, that way you don’t need to append += Vector3.new(0, 90, 0) to the instances’ “Orientation” property.