I’m trying to make a Screen Shake Effect based on distance from the character

I have an NPC that stomps the ground and i want to make it so the closer you are to the enemy when he stomps the ground the stronger the screen shake is, i know how to do a screen shake but i don’t know how to calculate the distance.

1 Like

You could multiply the screen shake’s power by how far the Player’s distance away from the NPC’s RootPart is. Something like this:

```
local ShakePower = math.clamp(Player:DistanceFromCharacter(NPCRootPart.Position), 0, 100)
local ShakeSub = 100 - ShakePower
--assuming you know the angling math
CFrame.Angles(Angle * ShakeSub, Angle2 * ShakeSub, Angle3 * ShakeSub)
```

4 Likes

This works perfectly!

Thanks allot!

1 Like