Well, I have a vehicle that works fine but it basically doesn’t act like any other vehicle would and I don’t know how to implement it. When I press ‘W’, if it’s tilted, it keeps going up like there’s no gravity(there is gravity). How would I fix this problem?
3 Likes
Well, it all depends on how you set up the object and how you move it around in the script.
Without more information or script snippets, it’s hard to help.
local CAS = game:GetService('ContextActionService')
local char = script.Parent
local humanoid = char:FindFirstChild('Humanoid')
local fwd = 0
local rote = 0
local key = Enum.KeyCode
local seat = nil
function MoveFwd(acName, acState)
if acName == 'Forward' and acState == Enum.UserInputState.Begin then
fwd = 10
elseif acName == 'Backward' and acState == Enum.UserInputState.Begin then
fwd = -10
else
fwd = 0
end
end
function Rot(acName, acState)
if acName == 'Left' and acState == Enum.UserInputState.Begin then
rote = 5
elseif acName == 'Right' and acState == Enum.UserInputState.Begin then
rote = -5
else
rote = 0
end
end
humanoid.seated:Connect(function(active, place)
if active and place:IsA('VehicleSeat') then
CAS:BindAction('Forward', MoveFwd, true, key['W'])
CAS:BindAction('Backward', MoveFwd, true, key['S'])
CAS:BindAction('Left', Rot, true, key['A'])
CAS:BindAction('Right', Rot, true, key['D'])
seat = place
elseif not active then
CAS:UnbindAction('Forward')
CAS:UnbindAction('Backward')
CAS:UnbindAction('Left')
CAS:UnbindAction('Right')
seat = nil
end
end)
game:GetService('RunService').RenderStepped:Connect(function()
if seat then
local bp = seat:WaitForChild('BodyPosition')
local bg = seat:WaitForChild('BodyGyro')
local vf = seat:WaitForChild('VectorForce')
--local bv = seat:WaitForChild('BodyVelocity')
local brightShell = seat.Parent:WaitForChild('BrightShell')
bp.Position = seat.Position + (seat.CFrame.LookVector * fwd)
bg.CFrame = seat.CFrame * CFrame.Angles(0, rote, 0)
end
end)
I want to know how actual cars/tanks work. How would I implement this to roblox? Would a rotating wheel be enough to move the tank or does roblox physics work different?