- What are you attempting to achieve? (Keep it simple and clear)
I’m creating hover car and I have successfully managed to program suspension system and it’s physics, but I have problems with controls of vehicle.
- What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
I don’t know what body movers should I use.
I tried Angular velocity, but it fails to update front direction of vehicle resulting in vehicle rotating, but continuing moving towards fixed direction.
- What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
I know I should be using vehicle seat, but I’m not using it now, I am testing this vehicle with Run(Player is not spawning) and I have runService loop which detects keys pressed and on desired ones applies forces of moving forward or backwards and turning. I think that’s where I have trouble. My loop doesn’t update Cframe.LookVector value
here’s the code:
game:GetService("RunService").Stepped:Connect(function()
local X = part.Velocity.X
local Y = part.Velocity.Y
local Z = part.Velocity.Z
--Resistance and Deaccelaration
part.Velocity = part.Velocity - part.Velocity/R
–
local function onKeyPress(inputObject, gameProcessedEvent)
--Forward
if inputObject.KeyCode == Enum.KeyCode.T then
thruster.Force = thruster.Force + part.CFrame.LookVector*10
end
--Backward
if inputObject.KeyCode == Enum.KeyCode.G then
thruster.Force = thruster.Force - part.CFrame.LookVector*10
end
--Turning Right
if (inputObject.KeyCode == Enum.KeyCode.T and UIS:IsKeyDown(Enum.KeyCode.H)) or (inputObject.KeyCode == Enum.KeyCode.H and UIS:IsKeyDown(Enum.KeyCode.T)) then
thruster.Force = thruster.Force + part.CFrame.LookVector*10
rotate1.AngularVelocity = Vector3.new(0,-2,0)
end
--Left
if (inputObject.KeyCode == Enum.KeyCode.T and UIS:IsKeyDown(Enum.KeyCode.F)) or (inputObject.KeyCode == Enum.KeyCode.F and UIS:IsKeyDown(Enum.KeyCode.T)) then
thruster.Force = thruster.Force + part.CFrame.LookVector*10
rotate1.AngularVelocity = Vector3.new(0,2,0)
end
--RotLeft
if inputObject.KeyCode == Enum.KeyCode.F then
rotate1.AngularVelocity = Vector3.new(0,2,0)
end
--RotRight
if inputObject.KeyCode == Enum.KeyCode.H then
rotate1.AngularVelocity = Vector3.new(0,-2,0)
end
end
local function onKeyLetgo(inputObject, gameProcessedEvent)
if (inputObject.KeyCode == Enum.KeyCode.T and inputObject.KeyCode == Enum.KeyCode.F)
or (inputObject.KeyCode == Enum.KeyCode.T and inputObject.KeyCode == Enum.KeyCode.H)
or (inputObject.KeyCode == Enum.KeyCode.G and inputObject.KeyCode == Enum.KeyCode.F)
or (inputObject.KeyCode == Enum.KeyCode.G and inputObject.KeyCode == Enum.KeyCode.H)
or inputObject.KeyCode == Enum.KeyCode.T
or inputObject.KeyCode == Enum.KeyCode.G
or inputObject.KeyCode == Enum.KeyCode.H
or inputObject.KeyCode == Enum.KeyCode.F then
thruster.Force = Vector3.new(0, thruster.Force.Y ,0)
rotate1.AngularVelocity = Vector3.new(0,0,0)
end
end
UIS.InputBegan:connect(onKeyPress)
UIS.InputEnded:connect(onKeyLetgo)
end)