i want to only tween the orientation of a character, im currently tweening both the character position and orientation and it makes the player freezes when it moves, is there a way to only tween the rotation of the character?
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
local humanoidrootpart = character:FindFirstChild("HumanoidRootPart")
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.W then
local goal = {}
goal.CFrame = CFrame.new(humanoidrootpart.Position) * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
local tween = TweenService:Create(humanoidrootpart, tweenInfo, goal)
tween:Play()
end
if input.KeyCode == Enum.KeyCode.S then
local goal = {}
goal.CFrame = CFrame.new(humanoidrootpart.Position) * CFrame.Angles(0, -180, 0)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
local tween = TweenService:Create(humanoidrootpart, tweenInfo, goal)
tween:Play()
end
end)
2 Likes
You cant use TweenService because it dosent use the physics engine, so if you want the character to rotate you should use physics constants. be sure to turn off AutoRotate
in the humanoid and disable first person view so the character dosent override it.
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = humanoidrootpart.CFrame
CFrameValue.Changed:Connect(function(newCFrame)
humanoidrootpart.CFrame = newCFrame
end
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.W then
local goal = {}
goal.CFrame = humanoidrootpart.CFrame * CFrame.Angles(0, 0, 0)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
local tween = TweenService:Create(CFrameValue, tweenInfo, goal)
tween:Play()
end
if input.KeyCode == Enum.KeyCode.S then
local goal = {}
goal.CFrame = humanoidrootpart.CFrame * CFrame.Angles(0, math.rad(-180), 0)
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back)
local tween = TweenService:Create(CFrameValue, tweenInfo, goal)
tween:Play()
end
end)
Hopefully this works. (maybe)
Edit:- Before testing this out, try changing goal.CFrame = humanoidrootpart.CFrame * CFrame.Angles(0, -180, 0)
to goal.CFrame = humanoidrootpart.CFrame * CFrame.Angles(0, math.rad(-180), 0)
2 Likes