Camera Bobble & POV script isn't functioning

When I take a single step, I die. I’m also trying to make it where the bottom part of the characters avatar is showing (excluding the head) but it’s not showing. Suggestions?

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

local cameraOffset = Vector3.new(0, 0.5, 0) 
local bobbleSpeed = 3 
local bobbleIntensity = 2
local fovIncrement = 10 

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")
	local rootPart = character:WaitForChild("HumanoidRootPart")
	local previousPosition = rootPart.Position
	local bobbleValue = 0
	local isRunning = false

	humanoid.Running:Connect(function(speed)
		if speed > 0 then
			if not isRunning then
				isRunning = true
				camera.FieldOfView += fovIncrement
			end

			while humanoid:GetState() == Enum.HumanoidStateType.Running do
				local currentPosition = rootPart.Position
				local movementDelta = (currentPosition - previousPosition).magnitude

				if movementDelta > 0 then
					bobbleValue = bobbleValue + movementDelta * bobbleSpeed
					local bobbleOffset = math.sin(bobbleValue) * bobbleIntensity

					camera.CFrame = CFrame.new(currentPosition + cameraOffset + Vector3.new(0, bobbleOffset, 0), currentPosition)
				end

				previousPosition = currentPosition
				wait()
			end

			if isRunning then
				camera.FieldOfView -= fovIncrement
				isRunning = false
			end
		else
			bobbleValue = 0
		end
	end)
end

player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
	onCharacterAdded(player.Character)
end

Personally I don’t think using Humanoid.Running is a good idea here, for a few reasons.

  1. It only updates when the HumanoidState is set to running (or stops running), and you’d be able to move the camera if you dont allow the state to update (either by staying in place or continuously running).
  2. It seems to fire a few times when changed? Like, 3 or 4 for some reason in my testing. Which is really odd.

Renderstepped is your friend when working with cameras. Here’s what I think you tried to achieve (top down camera?; your description was kinda weird).
Note: I used the spring module (made by blackshibe) for this. It’s perfect for this type of application.
TopDownCameraDemo.rbxl (46.8 KB)

local RunService = game:GetService("RunService")
local SpringModule = require(script.Spring) -- Set this to whereever you have the spring module located
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local CameraSpring = SpringModule.create()

local BobbleSettings = {
	BobbleSpeed = 0.4,
	BobbleIntensity = .5,
	FovIncrement = 10 
}

local CameraOffset = Vector3.new(0, 15, 0) 
local CameraConnection: RBXScriptConnection

local function onCharacterAdded(Character: Model)
	local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
	local HRP = Character:WaitForChild("HumanoidRootPart")
	local BobbleValue = 0
	local BobbleOffset = 0
	
	if CameraConnection then
		CameraConnection:Disconnect()
	end
	
	CameraConnection = RunService.RenderStepped:Connect(function (DT)
		local MoveMagnitude = Humanoid.MoveDirection.Magnitude
		
		if MoveMagnitude > 0.1 then -- I made the threshold 0.1 because sometimes you could be moving really slowly (pushing into a wall for example) and I thought that would look weird.
			BobbleValue = BobbleValue + Humanoid.WalkSpeed * BobbleSettings.BobbleSpeed * DT
			BobbleOffset = math.sin(BobbleValue) * BobbleSettings.BobbleIntensity
			
			CameraSpring:shove(Vector3.new(0, 0, BobbleOffset))
		end
		
		local MovementOffset = CameraSpring:update(DT)
		Camera.CFrame = CFrame.lookAt(HRP.Position + CameraOffset, HRP.Position) * CFrame.new(MovementOffset)
	end)
	
end

Player.CharacterAdded:Connect(onCharacterAdded)

Oh sorry for the description. But I wasn’t trying to go for a “Top Down camera” I wanted a camera in this view.

When you look down, you’ll see your torso, etc. Excluding the head of course. What I attempted to do in the script was have Camera Bobble & POV (this view) in the same script.

Well, I guess I’ll save the demo for some other person that might need that then lol.
As for seeing your own body then you can just change the LocalTransparencyModifier on a RenderStepped loop and you’ll be able to see it in first person.

Something like this should work:

local RunService = game:GetService("RunService")
local Camera = game.workspace.CurrentCamera
local Player = game.Players.LocalPlayer

RunService.RenderStepped:Connect(function ()
  local Character = Player.Character or Player.CharacterAdded:Wait()
	if (Camera.CFrame.Position - Camera.Focus.Position).Magnitude >= 1 then
        return
	end
     
    for _,Object in Character:GetDescendants do
         if Object:IsA("BasePart") and Object.Name ~= "Head" then
              Object.LocalTransparencyModifier = 0
           end
       end
end)

I didn’t test this and just wrote it quickly in the dev forum text editor so it might not work first try and you’ll probably have to mess with other stuff to get it working.

1 Like

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