It won’t be a problem since my game will be a first player game
I mean, it still would considering that again, even if you play alone, you are still connected to a server… it doesn’t just disappear and no one is the game ‘host.’
if you wanna do it, use playeradded and characteradded.
Hey I know im late on this but I wanted to use this and was wondering how can I make it work for if I’m going back and forth I know a good deal about scripting but never used most of the things used in this scripts and I couldn’t find any resources to read b=about some of the things either ik its probably easy but any help is appreciated
Tweak as necessary
task.wait(1.5)
local Player = game.Players.LocalPlayer
local TweenService = game:GetService("TweenService")
local root = Player.Character.HumanoidRootPart
local dir, vel
local angle = 0
local angle2 = 0
local original = root.RootJoint.C0
--looping code
local hb = game:GetService("RunService")
hb.Heartbeat:Connect(function()
if Player.Character.Humanoid.Health >= 1 then
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2 then
dir = vel.Unit
angle = root.CFrame.RightVector:Dot(dir)/6.5
angle2 = root.CFrame.LookVector:Dot(dir)/6.5
else
angle = 0
angle2 = 0
end
local tweenInfo = TweenInfo.new(
.2,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(root.RootJoint, tweenInfo, {C0 = original*CFrame.Angles(angle2, -angle, 0)})
tween:Play()
end
end)
It’s @Wunder_Wulfe 's code, except I’m just tweening the lookvector direction as well as the rightvector so you get the movement in both directions.
If anyone later on finds this article, I’ve manipulated the code to work for r15 characters, this is a script that goes inside of the startercharacter folder
local TweenService = game:GetService("TweenService")
local root = script.Parent:WaitForChild("LowerTorso")
local dir, vel
local angle = 0
local angle2 = 0
local original = root.Root.C0
local hb = game:GetService("RunService")
hb.Heartbeat:Connect(function()
if script.Parent.Humanoid.Health >= 1 then
vel = root.Velocity * Vector3.new(1,0,1)
if vel.Magnitude > 2 then
dir = vel.Unit
angle = root.CFrame.RightVector:Dot(dir)/4.5
angle2 = root.CFrame.LookVector:Dot(dir)/4.5
else
angle = 0
angle2 = 0
end
local tweenInfo = TweenInfo.new(
.2,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(root.Root, tweenInfo, {C0 = original*CFrame.Angles(-angle2, 0, -angle)})
tween:Play()
end
end)
use math.rad for what ever angle is
Thanks for creating the Script and it would be nice if there is an R15 and R6 Script Compatibility, I mean I would love if someone made a Script for the best of both worlds, Have a great day
I cleaned up and remade the code and also added an R6 or R15 compatible feature! It should be a LocalScript
that is located in StarterPlayer.StarterCharacterScripts
.
By the way, TILT_SIZE
in line 5 is customizable! Recommended values are around 100 to 750, you can change it to whatever you like. Feel free to take the code or learn something from it.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local TILT_SIZE = 250
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root
local RootJoint
local Angle1 = 0
local Angle2 = 0
local Direction
local Velocity
local ORIGINAL_C0
local CHARACTER_RIG_TYPE = Humanoid.RigType
if CHARACTER_RIG_TYPE == Enum.HumanoidRigType.R6 then
Root = Character:WaitForChild("Root")
RootJoint = Root:WaitForChild("RootJoint")
else
Root = Character:WaitForChild("LowerTorso")
RootJoint = Root:WaitForChild("Root")
end
ORIGINAL_C0 = RootJoint.C0
local function Heartbeat()
if Humanoid.Health > 0 then
Velocity = Root.Velocity * Vector3.new(1, 0, 1)
if Velocity.Magnitude > 2 then
Direction = Velocity.Unit
Angle1 = Root.CFrame.LookVector:Dot(Direction) / (1000 / TILT_SIZE)
Angle2 = Root.CFrame.RightVector:Dot(Direction) / (1000 / TILT_SIZE)
else
-- Resets the angles because player is moving too slow
Angle1 = 0
Angle2 = 0
end
local TiltGoal = {C0 = ORIGINAL_C0 * CFrame.Angles(Angle1, -Angle2, 0)}
local TiltTween = TweenService:Create(RootJoint, TweenInfo.new(0.2), TiltGoal)
TiltTween:Play()
end
end
RunService.Heartbeat:Connect(Heartbeat)
Oh thank you so much, you’re my hero! It pretty much works pretty well but it’s kinda hard to notice the tilting if the Player is using R6, but it’s better than nothing, Thank you, and have a great day!
Can you help me understand why the script would use the tween service for this?
The code is already executing every heartbeat, and smoothing the target value on each iteration.
It seems you could set the cframe directly, but the script creates a brand new tween every frame to do it instead.