Need help on a system were your camera shakes if a monster is following you or near you

Hello Everyone!

(Intro)

I’m DragonDarkVader A Roblox Developer with a big dreams (Including being part of Roblox RDC)

(My Plan)
I’m making the most advanced Horror game like Doors

(Something i need help with)

Anybody know how to make a system were if a monster is near you, Your camera will shake? (Like any monster whitelisted in the localscript/script/modulescript)

(Outro)

Thank you for all the help, I appreciate it!

3 Likes

u can use run service.renderstepped in a local script tp handle to camera shake. Also u need to calculate the position between the monster and the player.

(playerpos - monsterpos).magnitude -- Something like this 
1 Like

Where do i place it? (character limit)

you can use this module to do the camera shake: EZ Camera Shake ported to Roblox

and when the monster is in a certain range you can start shaking their screen

1 Like

Do you know how to script it? (character limit)

follow the module’s example code to setup the module then on a runservice renderstepped check the distance between the character and the monster using mangitude. then if they are in a certain range shake the camera

1 Like

oof, I do not know anything about scripting.

I would recommend looking up some tutorials by alvinblox or thedevking if you don’t know how to script. It’s going to be almost impossible to create a game as advanced as doors if you don’t have any scripting knowledge.

1 Like

Well that’s alright, Making the game i got a friend to help me. He’s offline right now so i’m asking on DevForum.

2 Likes

So do you know how to do it? (character limit)

like starterplayer script. not sure if its gonna work there, but give it a shot

1 Like

Hello, you can simply use CameraOffset in the Humanoid.

game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(0,0,0) -- Default to set it back

game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(3,1,5) -- You can just change these values to mess with the camera!

Also, this would work for calculating the distance between them, like he said.

local Distance = (playerpos - monsterpos).magnitude

This would be in studs if you were wondering. ^

Also, if you were wondering, yes, it works in First Person and Third Person.

2 Likes

So that would go to StarterPlayerScripts?

I’m not trying to sound mean, but you should really at least watch some scripting tutorials, and then if you can’t make it yourself, ask here.

5 Likes

StarterPlayerScripts would work, yes.

This would require a bit of work from both the server and the client.

In the monster, a script should be added, where when it’s chasing a player, it should add a localscript to the character and enable it. This localscript would be destroyed upon the monster no longer chasing the player.

For the client, you’d just need a simple script like so:

while task.wait(0.01) do
   game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(math.random(-1,1),math.random(-1,1),math.random(-1,1))
end

Hope this helps!

1 Like

This could easily be improved, I would always recommend using BindToRenderStep for things related the camera instead.

-- THIS IS PSEUDO CODE, AND WILL NOT WORK OUT OF THE BOX.
local RunService = game:GetService("RunService")

local function CameraShake()
    --camera stuff goes here
end)

RunService:BindToRenderStep("CameraShake", Enum.RenderPriority.Camera.Value + 1, CameraShake,)
3 Likes

Also instead of doing some hacky method of creating and destroying scripts, you can use remote events.

1 Like

Hello everyone! I am slowly improving my skills as a Roblox Programmer. Thank you for all your services and help contributed for me!

1 Like

Why are you asking about unrelated code issues on this thread? I would highly suggest making a new one.