When you want trigonometry work properly, something should decrease or increase constantly?
local RunService = game:GetService("RunService")
local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")
local function updateBobbleEffect()
local now = tick()
if humanoid.MoveDirection.Magnitude > 0 then -- Are we walking?
local velocity = humanoid.RootPart.Velocity
local bobble_X = math.cos(now * 9) / 5
local bobble_Y = math.abs(math.sin(now * 12)) / 5
local bobble = Vector3.new(bobble_X,bobble_Y,0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble,.25)
else
-- Scale down the CameraOffset so that it shifts back to its regular position.
humanoid.CameraOffset = humanoid.CameraOffset * 0.75
end
end
-- Update the effect on every single frame.
RunService.RenderStepped:Connect(updateBobbleEffect)
In here there is
local now = tick()
this one is increasing constantly and providing trigonometry work.I just tried to use this script without tick() but it does’nt work. I will give you one more example:
local RunService = game:GetService("RunService")
local plr = game.Players.LocalPlayer
local chr = plr.Character
local humrootpart = chr:WaitForChild("HumanoidRootPart")
local hum = chr:WaitForChild("Humanoid")
local cam = workspace.Camera
local tiltSpeedZ = 0.1
local bobbingSpeed = 0.1
local tilt = 0
local sinValue = 0
function lerp(a, b, t)
return a + (b - a) * t
end
function calculateSine(speed, intensity)
sinValue += speed
if sinValue > (math.pi * 2) then sinValue = 0 end
local sineY = intensity * math.sin(2 * sinValue)
local sineX = intensity * math.sin(sinValue)
local sineCFrame = CFrame.new(sineX, sineY, 0)
return sineCFrame
end
local previousSineX = 0
local previousSineY = 0
RunService.RenderStepped:Connect(function(dt)
local movementVector = cam.CFrame:vectorToObjectSpace(humrootpart.Velocity / math.max(hum.WalkSpeed, 0.01))
local speedModifier = (hum.WalkSpeed / 16)
tilt = math.clamp(lerp(tilt, movementVector.X * tiltSpeedZ, 0.1), -0.25, 0.1)
local sineCFrame = calculateSine(bobbingSpeed * speedModifier, movementVector.Z * speedModifier)
local lerpedSineX = lerp(previousSineX, sineCFrame.X, 0.1)
local lerpedSineY = lerp(previousSineY, sineCFrame.Y, 0.1)
cam.CFrame *= CFrame.Angles(0, 0, tilt) * CFrame.new(lerpedSineX, lerpedSineY, 0)
previousSineX = lerpedSineX
previousSineY = lerpedSineY
end)
I also checked this. This script was made by @RoyalTHEUSERNAME. I just used it for advice. This script has a “speed” variable that changes based on the player’s walking speed. If you think about how this script works, it actually provides the view bobbing without constant variable. Just changes when player changes speed.
Basically if we come to my issue according to this examples, when i use non-constant variables my positioning or somethings like that does’nt work. For example i wanted to change position of the part to near of spawnpoint:
and i just made a script that is this:
local Part = game.Workspace.Part
local SpawnPoint = game.Workspace.SpawnLocation
local Position = SpawnPoint.Position * Vector3.new(math.sin(math.pi/4) * 5,math.cos(math.pi*4) * 5,0)
Part.Position = Position
When i press play part goes to here:
This script is incorrect or im doing something wrong?
This examples must be enough. Im still not ensure this script is right since because im feeling somethings is missing. Yeah if it like that i will feel really dumb. Thanks in advance