I have been trying to make a tank movement system for my game but I have been stuck on trying to rotate the player when A or D is pressed but the tank modal is not rotating with the HumanoidRootPart and the rotation is reset after the player moves
(A simplified version of my code)
(Also I am using a simple state machine for the held variables)
local MoveSpeed = 0.25
local WIsHeld = false
local AIsHeld = false
local HumanRoot = script.Parent:WaitForChild("HumanoidRootPart")
while true do
if WIsHeld then
script.Parent:PivotTo(CFrame.new(script.Parent:GetPivot().Position + HumanRoot.CFrame.LookVector * MoveSpeed))
end
if AIsHeld then
local NewOrientation = HumanRoot.Orientation + Vector3.new(0,1,0)
script.Parent.PrimaryPart.Orientation = NewOrientation
end
task.wait(0.01)
end
local MoveSpeed = 0.25
local WIsHeld = false
local AIsHeld = false
local HumanRoot = script.Parent:WaitForChild("HumanoidRootPart")
while true do
if WIsHeld then
script.Parent:PivotTo(CFrame.new(script.Parent:GetPivot().Position + HumanRoot.CFrame.LookVector * MoveSpeed))
end
if AIsHeld then
local NewOrientation = HumanRoot.Orientation + Vector3.new(0,1,0)
script.Parent.PrimaryPart.CFrame *= CFrame.Angles(math.rad(NewOrientation.X), math.rad(NewOrientation.Y), math.rad(NewOrientation.Z))
--script.Parent.PrimaryPart.Orientation = NewOrientation
end
task.wait(0.01)
end
local MoveSpeed = 0.25
local WIsHeld = false
local AIsHeld = false
local HumanRoot = script.Parent:WaitForChild("HumanoidRootPart")
while true do
local cframe = CFrame.new(0, 0, 0)
if WIsHeld then
cframe *= CFrame.new(0, 0, -MoveSpeed)
end
if AIsHeld then
cframe *= CFrame.Angles(0, math.rad(1), 0)
end
script.Parent:PivotTo(script.Parent:GetPivot() * cframe)
task.wait(0.01)
end
I solved the no rotating problem by using this in the
If AIsHeld then
script.Parent:PivotTo(CFrame.new(script.Parent:GetPivot().Position) * CFrame.Angles(math.rad(NewOrientation.X),math.rad(NewOrientation.Y),math.rad(NewOrientation.Z)
end