What do you want to achieve?
Currently, I’m trying to get a viewbob similar to that of Half-Life. You may have seen it before, but if you haven’t, here’s a mp4 of it.
What is the issue?
I actually came across a Unity project that has this implemented, and I even tried to convert it to Roblox Lua. However, this didn’t work, as it has a single thing that isn’t in the lua documentations that I’m aware of; and that thing is Time.time
This function, according to the unity documentations, gets the amount of time in seconds that the application has been running for. But, I don’t think that would work very well, because Roblox uses servers, and isn’t a standalone application like Unity is.
What solutions have you tried so far?
I have tried many things so far, even looked for similar functions on Developer Hub. But, it still doesn’t work.
Could somebody help me rid the use of “Time.time” in this; and maybe potentially fix any other issues that come up, if I can’t fix them myself? Please, and thank you.
Seriously hope I’m not asking for too much here.
Here’s my code if you need it.
local cameraBasePosition
local gunBasePosition
local gunBaseRotation
local shootOffset = Vector3.new(0,0,0);
module.targetShootOffset = Vector3.new(0,0,0);
local shootRotationOffset = Vector3.new(0,0,0);
module.targetShootRotationOffset = Vector3.new(0,0,0);
module.shakeSpeed = 1.0;
local Time = 0.0;
local NUTility = require(script.Parent:WaitForChild("NUtility"))
-- Use this for init
function module.Start(viewmodel)
cameraBasePosition = workspace.CurrentCamera.CFrame.Position
gunBaseRotation = viewmodel.Head.Orientation
gunBasePosition = viewmodel.Head.Position
end
function module:CalculateViewbob(viewmodel, char)
-- Update the gunBaseRotation and gunBasePosition
gunBasePosition = viewmodel:WaitForChild("Head").Position
-- do some funnies
local playerSpeed = math.min(NUTility:GetXZ(char.HumanoidRootPart.Velocity).magnitude / 15.0, 0.6)
shootOffset = shootOffset:Lerp(module.targetShootOffset, 0.2)
shootRotationOffset = shootRotationOffset:Lerp(module.targetShootRotationOffset, 0.2)
Time += module.shakeSpeed;
-- Gun
-- Position
local pos = gunBasePosition + shootOffset;
pos = pos + Vector3.new((math.sin(tick + Time * 0.5) * 0.01), 0, 0) -- X
pos = pos + Vector3.new(0,(math.sin(tick + Time * 0.25) * 0.01),0) -- Y
pos = pos + Vector3.new(0,0,(math.sin(tick * 8) * 0.1 * playerSpeed)) -- Z
return pos -- Returns the new position that it created
end
return module
Any help would be appreciated!