It does what I want it to do I just dont want it to change directions so suddenly. Is there a way I can combine the CFrame.lookAt and the CFrame.Angles in or to make all of its movement smooth.
When I do it, the CFrame.lookAt doesn’t change directions suddenly adapting from my old tilt script which also modifies the C1 and now uses CFrame.lookAt.
The only bug is with humanoids as they don’t like the character being horizontal.
StarterCharacerScripts
local localPlayer = game:GetService("Players").LocalPlayer
local Character = localPlayer.Character or localPlayer.CharacterAdded:wait()
local lowerTorso = Character:WaitForChild("LowerTorso")
local humanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local normalize = Vector3.new(1,0,1)
local c1Store = lowerTorso.Root.C1
local tiltFactor = 2.5
local camera = Workspace.CurrentCamera
local ZEROVECTOR = Vector3.new(0,0,0)
game:GetService("RunService").RenderStepped:Connect(function()
local movementVector = humanoidRootPart.Velocity*normalize*tiltFactor
movementVector = (humanoidRootPart.CFrame-humanoidRootPart.CFrame.p):Inverse()*movementVector
local x = math.rad(movementVector.X)
local z = math.rad(movementVector.Z)
local goalCFrame = CFrame.Angles(-z,0,x)
humanoidRootPart.CFrame = CFrame.lookAt(ZEROVECTOR,camera.CFrame.LookVector*Vector3.new(1,0,1))+humanoidRootPart.Position
lowerTorso.Root.C1 = lowerTorso.Root.C1:Lerp(goalCFrame,0.25)
end)
Make sure it’s in render stepped, as it needs to be in synced with camera movement. It feels like something is delaying the camera CFrame from updating and hence the sudden change in direction which is odd.
Also make sure to math.min the lerp alpha value to make sure it doesn’t go over the goal by 1 no matter what happens. It gets buggy if it does that.
My bad I probably should have gave more information. I have it so the direction only changes when i move the drone, which is what causes the sudden direction change, I just want to know how to make it do that smoothly whenever I move it instead of facing forward instantly.