Wrong part orientation by locking first person

I made this script to achieve an “anime wind” style speed animation using particles and CFrame for locking it at the Camera, but somewhy it’s doing half the job…

Here’s what’s happening:

And here’s the parents from the script, if needed.
image

Script:

local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local DashParticles = script.Parent


local function updateObject()
	local cameraCFrame = Camera.CFrame

	DashParticles.Position = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
	RunService.RenderStepped:Connect(function()
		wait()
		DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, Camera.CFrame.Position)*CFrame.Angles(math.rad(90),0, 0)		
	end)

end


updateObject()
Camera:GetPropertyChangedSignal("CFrame"):Connect(updateObject)
1 Like

I think instead, you should get the camera’s LookVector and add that to the dash particle’s position:

-- DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, Camera.CFrame.Position)*CFrame.Angles(math.rad(90),0, 0)	
DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, DashParticles.Position + -Camera.CFrame.LookAt)*CFrame.Angles(math.rad(90),0, 0)	

Using the camera’s position would be where you’ve stationed your camera in your client. So, whenever you go in first person, the orientation will look downwards/upwards since it’s positioned near your dash particles.

Let us know how this goes.

Works flawlessly!

Thank you so much!

By now, just one more question: Is there a way to make the particles move a little bit further to the front? Like, move them a bit to the front to give it more particles to the screen?

As you see on the video, the quantity of particles is low because of the distance between the center of the object from the camera.

But by now, thank youuu!!!

1 Like

You’re welcome! And to further help you with this,

Yeah, there’s a way you can do that. We could actually rework the code to add an offset to the dash’s CFrame:

-- DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, Camera.CFrame.Position)*CFrame.Angles(math.rad(90),0, 0)	
-- DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, DashParticles.Position + -Camera.CFrame.LookAt)*CFrame.Angles(math.rad(90),0, 0)	

local offset = Vector3.new(0, 0, 1) -- it's in respective to the player's camera space.

DashParticles.CFrame = CFrame.lookAt(DashParticles.Position, DashParticles.Position + -Camera.CFrame.LookAt) * CFrame.Angles(math.rad(90),0, 0) + Camera.CFrame:VectorToWorldSpace(offset)

And for future reference, I do suggest you learn more about CFrames. They’re going to be quite useful and/or mandatory in your game from the looks of things. Here are also some videos that explain it in a more simplistic way:

Though, if you want a more personal explanation, you can always PM me and I can help you from there.

1 Like

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