Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help on camera manipulation, have any idea?

Asked by 9 years ago

In my game, I want a sound to play when you are put in FPS mode, but I need to know how it would sound only at that point, does anyone have any idea how this would work? I know you wouldn't use FieldOfView becuase that changes everything around... Can anyone please help me?

1 answer

Log in to vote
0
Answered by
Tuneable 100
9 years ago

The best way to do this is check the distance between the CurrentCamera and the Head. I would use magnitude for this like so

local Magnitude = (CurrentCamera.CoordinateFrame.p - Head.CFrame.p).magnitude

Usually the magnitude is around 1 stud when you are zoomed into first person.

if Magnitude <= 1 then
-- do stuff()
end

To make this work though, you would have to put this in a while loop because I'm pretty sure .Changed doesn't fire for CoordinateFrame. Also, to make your sound only run when you get put in first person, we can make a variable named ZoomedIn and if it is already true than not play the sound.


local ZoomedIn = false while true do wait(.01) local Magnitude = (CurrentCamera.CoordinateFrame.p - Head.CFrame.p).magnitude if Magnitude <= 1 and ZoomedIn == false then -- sound stuff ZoomedIn = true else ZoomedIn = false end end
0
Thank you, I nknow how to do the rest, I just needed help to find the one property, thank you. rollercoaster57 65 — 9y
0
why is there a either A missing parentheses, or B, extra parenteheses? rollercoaster57 65 — 9y
0
Woops I accidentally put parenthesis after .magnitude. I'll edit the post Tuneable 100 — 9y
0
Thanks, i was a bit confused... rollercoaster57 65 — 9y
0
Also, instead of it being a variable, I just did an elseif statement instead of just an else rollercoaster57 65 — 9y
Ad

Answer this question