Moving part forward in camera direction

I may just be dumb but the title says it all,

How do I move a part forward relative to camera LookVector via CFrame

aswell as relative to movedirection

Thanks in advance

Directly relative to the cam CFrame?

Get the cam CFrame and just multiply by a Camera.CFrame = Camera.CFrame * CFrame.new(0,0,-5)

I mean like the way the camera is looking aswell as relative to the characters movedirection from humanoid

Relative to the Character CFrame and relative to the Camera CFrame?
That would be 2 points to get a mid CFrame between both points.

Whats the exact purpose for the system? or what you have until now?

The exact purpose is a fly script using cframe for this project:
image

you are looking for moving the Character to the camera CFrame forward point?

In which method you will perform the task?
Moving the character with MoverConstraints, BodyMovers, or directly changing the HRP CFrame?
On what kind of loop? RunService step?

The final script would depend on those questions, cause you can simply set the HRP/PrimaryPart CFrame of the Character to the value gotten from camera.CFrame * CFrame.new(0,0,-1). And you would be repositioning the character 1 stud forward according to where the camera is aming. But that would require a loop that updates the position, and if you are using MoverConstrains or BodyMovers or just the CFrame, you would require different data and different ways of achieving it

Yes, I am using a while task.wait() do loop and direct HRP CFraming,

But I’m also trying to use MoveDirection to move the character in any direction via wsad

Used this method, did not work well.

character.HumanoidRootPart.CFrame:Lerp(character.HumanoidRootPart.CFrame * workspace.CurrentCamera.CFrame * CFrame.new(0,0,-1) + character.Humanoid.MoveDirection, character.Humanoid.WalkSpeed/100)

I think you should show the entire script so we have a better idea on how it should work

Dont mind the spaghetti code, only pay attention to the two lines related to the HRP


spawn(function()
	character.Parent = Instance.new("WorldModel",workspace)
	
	cwm = character.Parent

	while task.wait() do
		pcall(function()
			sine = sine + 1

			if not character.Parent:IsA("WorldModel") then
				character.Parent = Instance.new("WorldModel",workspace.Terrain)
				cwm = character.Parent
			end
			if character.Humanoid.MoveDirection ~= Vector3.new() then
				if mode == 1 then
					cwelds["weldt5"].C0 = cwelds["weldt5"].C0:Lerp(cf(0,2,1) * cf(0,-math.cos((sine / 6) / 6) * 0.4,0) * angles(math.rad(-80),0,math.rad(math.cos((sine / 7) / 7) * 3)),0.1)
					cwelds["weldt"].C0 = cwelds["weldt"].C0:Lerp(cf(-1.5,0.1,0) * angles(math.rad(math.sin((sine / 5) / 5) * 3),math.rad(math.sin((sine / 5) / 5) * -3),0),0.1)
					cwelds["weldt1"].C0 = cwelds["weldt1"].C0:Lerp(cf(1.5,0.1,0) * angles(math.rad(math.sin((sine / 5) / 5) * -3),math.rad(math.sin((sine / 5) / 5) * 3),0),0.1)
					cwelds["weldt2"].C0 = cwelds["weldt2"].C0:Lerp(cf(-0.5,-2,0) * angles(math.rad(math.sin((sine / 5) / 5) * 3),math.rad(math.sin((sine / 5) / 5) * -3),0),0.1)
					cwelds["weldt3"].C0 = cwelds["weldt3"].C0:Lerp(cf(0.5,-2,-0.2) * angles(0,math.rad(8),0) * angles(math.rad(math.sin((sine / 5) / 5) * 3),math.rad(math.sin((sine / 5) / 5) * -5),0),0.1)
					cwelds["weldt4"].C0 = cwelds["weldt4"].C0:Lerp(cf(0,1.4,0.2) * angles(math.rad(50),0,0) * angles(math.rad(math.sin((sine / 5) / 5) * 3),0,0),0.1)
					cwelds["weldt6"].C0 = cwelds["weldt6"].C0:Lerp(cf(0,-1.2,0) * cf(0,math.sin((sine / 6) / 6) * 0.02,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 8 / 2)),0,0) * angles(math.rad(-52),0,0),0.1)
				elseif mode == 2 then
					cwelds["weldt5"].C0 = cwelds["weldt5"].C0:Lerp(cf(0,-0,0) * angles(math.rad(-30),math.rad(math.cos((sine / 3) / 3) * 7),0),0.1)
					cwelds["weldt"].C0 = cwelds["weldt"].C0:Lerp(cf(-1.5,-0.2,0.3) * angles(math.rad(-30),math.rad(math.cos((sine / 5) / 5) * 4),0),0.1)
					cwelds["weldt1"].C0 = cwelds["weldt1"].C0:Lerp(cf(1.5,-0.2,0.3) * angles(math.rad(-30),math.rad(math.cos((sine / 5) / 5) * 4),0),0.1)
					cwelds["weldt3"].C0 = cwelds["weldt3"].C0:Lerp(cf(0.5,-2,0) * cf(0,0,math.cos((sine / 3) / 3) * -0.4) * angles(math.rad(math.cos((sine / 3) / 3) * 40),0,0),0.1)
					cwelds["weldt2"].C0 = cwelds["weldt2"].C0:Lerp(cf(-0.5,-2,0) * cf(0,0,math.cos((sine / 3) / 3) * 0.4) * angles(math.rad(math.cos((sine / 3) / 3) * -40),0,0),0.1)
					cwelds["weldt4"].C0 = cwelds["weldt4"].C0:Lerp(cf(0,1.5,0.1) * cf(0,0,math.cos((sine / 3) / 3) * 0.065) * angles(math.rad(30),math.rad(math.cos((sine / 3) / 3) * -7),0),0.1)
					cwelds["weldt6"].C0 = cwelds["weldt6"].C0:Lerp(cf(0,-1.2,0) * cf(0,math.sin((sine / 6) / 6) * 0.02,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 8 / 2)),0,0) * angles(math.rad(-52),0,0),0.1)
				end
				character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(character.HumanoidRootPart.CFrame * workspace.CurrentCamera.CFrame * CFrame.new(0,0,-1) + character.Humanoid.MoveDirection, character.Humanoid.WalkSpeed/100)
				character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(CFrame.lookAt(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + character.Humanoid.MoveDirection), 11/100)
			else
				if mode == 1 then
					cwelds["weldt5"].C0 = cwelds["weldt5"].C0:Lerp(cf(0,2,1) * cf(0,-math.cos((sine / 6) / 6) * 0.4,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 30 / 2)),math.rad(math.cos((sine / 7) / 7) * 2),math.rad(math.cos((sine / 7) / 7) * 3)) * angles(math.rad(40),0,0),0.1)
					cwelds["weldt"].C0 = cwelds["weldt"].C0:Lerp(cf(-1.6,-0.1,-0.4) * angles(math.rad(62),math.rad(20),math.rad(-12)) * angles(math.rad(0.5 + (math.sin((sine / 7) / 7) * 20 / 2)),0,0),0.1)
					cwelds["weldt1"].C0 = cwelds["weldt1"].C0:Lerp(cf(1.6,-0.1,0) * angles(math.rad(0),math.rad(-20),math.rad(12)) * angles(math.rad(0.5 + (math.sin((sine / 7) / 7) * 25 / 2)),0,0),0.1)
					cwelds["weldt2"].C0 = cwelds["weldt2"].C0:Lerp(cf(-0.7,-1.8,-0.3) * angles(math.rad(-62),math.rad(20),math.rad(12)) * angles(math.rad(0.5 + (math.sin((sine / 7) / 7) * 20 / 2)),0,0),0.1)
					cwelds["weldt3"].C0 = cwelds["weldt3"].C0:Lerp(cf(0.7,-2.1,0.05) * angles(math.rad(-9),math.rad(-20),math.rad(12)) * angles(math.rad(0.5 + (math.sin((sine / 8) / 8) * 25 / 2)),0,0),0.1)
					cwelds["weldt4"].C0 = cwelds["weldt4"].C0:Lerp(cf(0,1.6,-0.4) * cf(0,math.sin((sine / 6) / 6) * 0.02,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 8 / 2)),0,0) * angles(math.rad(-40),math.rad(10),0),0.1)
					cwelds["weldt6"].C0 = cwelds["weldt6"].C0:Lerp(cf(0,-1.2,0) * cf(0,math.sin((sine / 6) / 6) * 0.02,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 8 / 2)),0,0) * angles(math.rad(6),0,0),0.1)
				elseif mode == 2 then
					cwelds["weldt5"].C0 = cwelds["weldt5"].C0:Lerp(cf(0,7,0) * cf(0,0.5 + (math.sin((sine / 6) / 6) * 5 / 2),0) * angles(0,math.rad(-40),math.rad(0)) * angles(0,0,math.rad(math.sin((sine / 7) / 7) * 12)),0.1)
					cwelds["weldt"].C0 = cwelds["weldt"].C0:Lerp(cf(-0.5,-0.2,-0.3) * angles(math.rad(90),math.rad(-10),math.rad(60)) * angles(math.rad(math.sin((sine / 5) / 5) * 4),math.rad(math.cos((sine / 5) / 5) * 13),math.rad(math.sin((sine / 5) / 5) * -4)),0.1)
					cwelds["weldt1"].C0 = cwelds["weldt1"].C0:Lerp(cf(0.2,0.4,-0.5) * angles(math.rad(180),math.rad(-12),math.rad(5)) * angles(math.rad(math.sin((sine / 5) / 5) * 7),math.rad(math.sin((sine / 5) / 5) * -12),math.rad(math.sin((sine / 5) / 5) * -3)),0.1)
					cwelds["weldt3"].C0 = cwelds["weldt3"].C0:Lerp(cf(0.5,-1.875,-0.1) * angles(math.rad(-6),math.rad(-12),0),0.1)
					cwelds["weldt2"].C0 = cwelds["weldt2"].C0:Lerp(cf(-0.5,-1.25,-0.5) * angles(math.rad(-30),math.rad(4),0),0.1)
					cwelds["weldt4"].C0 = cwelds["weldt4"].C0:Lerp(cf(0,1.5,-0.05) * cf(0,0,math.cos((sine / 6) / 6) * -0.025) * angles(math.rad(-6),math.rad(math.cos((sine / 4) / 4) * -1),0) * angles(math.rad(math.cos((sine / 5) / 5) * 3),0,0),0.1)
					cwelds["weldt6"].C0 = cwelds["weldt6"].C0:Lerp(cf(0,-1.2,0) * cf(0,math.sin((sine / 6) / 6) * 0.02,0) * angles(math.rad(0.5 + (math.sin((sine / 6) / 6) * 8 / 2)),0,0) * angles(math.rad(6),math.rad(-192),0),0.1)
				end
			end
		end)
	end
end)

the main part to worry about is here

	character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(character.HumanoidRootPart.CFrame * workspace.CurrentCamera.CFrame * CFrame.new(0,0,-1) + character.Humanoid.MoveDirection, character.Humanoid.WalkSpeed/100)
				character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(CFrame.lookAt(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + character.Humanoid.MoveDirection), 11/100)
			

Yup, I understand what you are trying to do.
Theres modes of flying that are based as you said in character moving detection too…

Honestly I never made a flying system, I would only suggest to change the approach… But that would depends on the desired result you want as visuals.
Personally I dont think its necesary to perform a check of the character moving direction in that way, rotating the character according to the camera or the camera forward point would be enough to make it fly and turn based on camera position.

Sorry I cant help further, I would need some testing with that script or rebuilding entire approach, the only thing I noticed about what I suggested as using the camera CFrame wont work with that set up, and this line I guess should not multiply HRP.CFrame, only Camera.

character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(character.HumanoidRootPart.CFrame * workspace.CurrentCamera.CFrame * CFrame.new(0,0,-1) + character.Humanoid.MoveDirection, character.Humanoid.WalkSpeed/100)

Edit:
character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(workspace.CurrentCamera.CFrame * CFrame.new(0,0,-1) + character.Humanoid.MoveDirection, character.Humanoid.WalkSpeed/100)

And not +character.Humanoid.MoveDirection. But better ignore what I said, probably its for a different approach for a flying system

Your edit does actually semi work, It just requires some more editing to make it actually move forward, since currently it just goes to a single spot.

I can do that part myself,
thank you!

1 Like

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