Before I was a Roblox developer, sometimes when I got off vehicles it would cause me to get flinged each time I Jumped. Now its happening to me, I know body velocity is deprecated, but im still using it as im reusing a script and I don’t want to change the whole system. I have a spaceship which, when I jump off, its like gravity switched sideways and im being pushed by a force against to the wall. I have no idea why this is happening, but when the character gets off the seat, I anchored the ship models primary part and then make body velocity to 0,0,0, that’s all I got, so, how do I fix this?
can you show us a video AND script AND image of your workspace of the car?
can you show the other things i mentioned?
local seat = script.Parent
local oldChar = nil
local char
local function unAnchor(obj)
task.wait(.5)
obj.Anchored = false
end
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant ~= nil then
char = seat.Occupant.Parent
oldChar = char.Name
game.ReplicatedStorage.remotes.shipSetup:FireClient(game.Players:FindFirstChild(char.Name), seat)
end
if seat.Occupant == nil then
script.Parent.BodyVelocity.Velocity = Vector3.new(0,0,0)
if char then
char.HumanoidRootPart.Anchored = true
end
task.spawn(unAnchor, char.HumanoidRootPart)
game.ReplicatedStorage.remotes.shipStop:FireClient(game.Players:FindFirstChild(oldChar), seat)
oldChar = nil
end
end)
Server ^
local player = game.Players.LocalPlayer
local switch = false
local debounce = false
local equipped = nil
local gui = nil
local veri = 0
local gyro = nil
local leftRoll = nil
local rightRoll = nil
local leftRollUp = nil
local rightRollUp = nil
local start = nil
local stop = nil
local left = nil
local right = nil
local pulseDrive = nil
local pulseDrive2 = nil
local mouseEvent = nil
local forward = nil
local backward = nil
local forwardUp = nil
local backwardUp = nil
local up = nil
local down = nil
local upUp = nil
local downUp = nil
local ctrlBind = {}
ctrlBind.Top = "r"
ctrlBind.Bottom = "f"
ctrlBind.Front = "w"
ctrlBind.Back = "s"
ctrlBind.Left = "a"
ctrlBind.Right = "d"
ctrlBind.Controls = "c"
fastKey = "h"
signal = 0
ctrlBool = {}
ve = 0
oSpeed = 0
vec = 0
mo = 0
firing = false
fastOn = false
function getThrust(seat)
return 10
end
function hasWormholeTech(seat)
return true
end
function hasFTLTech(seat)
return true
end
function accountThrusters(thrusters)
return .6
end
function getMass(seat)
return 10
end
for i, m in pairs(ctrlBind) do
ctrlBool[i] = false
end
function turnDirectionConform(vector,vector2)
local e = vector2*CFrame.new(-1,0,0)
local b = vector2*CFrame.new(1,0,0)
local z = vector2 + vector
local left = e-z.p
local right = b-z.p
if left.p.Magnitude > right.p.Magnitude then return 1 end
return -1
end
function updateVectors(cam, mouse,seat)
local lookVector = cam.CFrame.LookVector
local optimalCF = seat.CFrame.p
local dir = CFrame.new(Vector3.new(), (lookVector) + seat.CFrame.lookVector)
local cf = dir
local lv = dir.lookVector
local cframe = dir
local tab = {}
tab.Vector = Vector3.new()
for i, m in pairs(ctrlBool) do
if i ~= "Fast" and i ~= "Controls" then
if Enum.NormalId[i] and m then
tab.Vector = tab.Vector + Vector3.FromNormalId(Enum.NormalId[i])
end
end
end
local finalVector = CFrame.new(tab.Vector.Unit.Magnitude < 5 and tab.Vector.Unit or Vector3.new())
local turning = dir.lookVector:Dot(seat.BodyGyro.cframe.lookVector)
ve = ve + vec
if vec == 0 then
ve = 0
end
local turn = ((lookVector) - seat.CFrame.lookVector).Magnitude
local ver = ve * 6
if gyro then
local g = (dir *CFrame.fromEulerAnglesXYZ(0, 0, math.rad(ver/3) + (turn * -turnDirectionConform((mouse.UnitRay.Direction), seat.CFrame))))
seat.BodyGyro.cframe = CFrame.new(Vector3.new(),g.lookVector - Vector3.new(0,g.lookVector.y,0))
else
seat.BodyGyro.cframe = dir *CFrame.fromEulerAnglesXYZ(0, 0, math.rad(ver/3) + (turn * -turnDirectionConform((mouse.UnitRay.Direction), seat.CFrame)))
end
local finalCFrame = CFrame.new(Vector3.new(),seat.CFrame.lookVector):toWorldSpace(finalVector)
if veri then
oSpeed = math.min(math.max(oSpeed + veri,0),1)
end
local Velocity = finalCFrame.p * (4 + (accountThrusters(getThrust(seat))*4000)/getMass(seat)) * oSpeed
if not overridePos then
seat.BodyVelocity.Velocity = seat.BodyVelocity.Velocity:Lerp(Velocity,0.1)
else
oSpeed = 600
seat.BodyVelocity.Velocity = (overridePos - seat.Position) * 18
if (overridePos - seat.Position).Magnitude < 60 then
overridePos = nil
oSpeed = .3
end
end
if on then
seat.BodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)*3000
seat.BodyVelocity.MaxForce = Vector3.new(400000, 400000, 400000)*3000
else
seat.BodyGyro.MaxTorque = Vector3.new(400000, 400000, 400000)*00
seat.BodyVelocity.MaxForce = Vector3.new(400000, 400000, 400000)*00
end
end
local lastChar = nil
game.ReplicatedStorage.remotes.shipSetup.OnClientEvent:Connect(function(seat)
if seat.Occupant ~= nil then
local char = player.Character
if char.Name == player.Character.Name then
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, true)
local mouse = player:GetMouse()
gui = game.ReplicatedStorage.SHIP_GUI:Clone()
lastChar = char
local cam = workspace.CurrentCamera
--cam.CameraType = "Attach"
equipped = true
gui.Parent = player.PlayerGui
on = seat.On.Value
--mouse.TargetFilter = workspace
forward = gui.forwardButton.MouseButton1Down:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "w" then
ctrlBool[i] = true
end
end
end)
forwardUp = gui.forwardButton.MouseButton1Up:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "w" then
ctrlBool[i] = false
end
end
end)
backward = gui.backwardButton.MouseButton1Down:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "s" then
ctrlBool[i] = true
end
end
end)
backwardUp = gui.backwardButton.MouseButton1Up:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "s" then
ctrlBool[i] = false
end
end
end)
up = gui.upButton.MouseButton1Down:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "r" then
ctrlBool[i] = true
end
end
end)
upUp = gui.upButton.MouseButton1Up:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "r" then
ctrlBool[i] = false
end
end
end)
down = gui.downButton.MouseButton1Down:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "f" then
ctrlBool[i] = true
end
end
end)
downUp = gui.downButton.MouseButton1Up:Connect(function()
for i, m in pairs(ctrlBind) do
if m == "f" then
ctrlBool[i] = false
end
end
end)
leftRoll = gui.leftRollButton.MouseButton1Down:Connect(function()
vec = 1
end)
rightRoll = gui.rightRollButton.MouseButton1Down:Connect(function()
vec = -1
end)
pulseDrive = gui.pulseDriveButton.MouseButton1Down:Connect(function()
if not fastOn then
fastOn = true
else
fastOn = false
end
end)
stop = gui.stopButton.MouseButton1Down:Connect(function()
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, true)
on = false
seat.On.Value = on
workspace.CurrentCamera.CameraSubject = player.Character
local bool = "no"
if overridePos then
oSpeed = 1
end
overridePos = nil
end)
start = gui.startButton.MouseButton1Down:Connect(function()
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, false)
on = true
workspace.CurrentCamera.CameraSubject = seat
local bool = "no"
seat.On.Value = on
oSpeed = 0.2
end)
pulseDrive2 = gui.pulseDriveButton.MouseButton1Down:Connect(function()
if hasFTLTech(seat) then
if oSpeed == 3.3 then return end
for _, v in next, seat.Parent:GetChildren() do
if v.ClassName == "Sound" then
v:Destroy()
end
end
wait(.75)
local sound = Instance.new("Sound", seat)
sound.SoundId = "rbxassetid://1837830825"
sound.Volume = 4
sound.RollOffMaxDistance = 100
sound:Play()
local bool = "yes"
oSpeed = 3.3
end
end)
leftRollUp = gui.leftRollButton.MouseButton1Up:Connect(function()
vec = 0
end)
rightRollUp = gui.rightRollButton.MouseButton1Up:Connect(function()
vec = 0
end)
mouseEvent = mouse.KeyDown:connect(function(key)
for i, m in pairs(ctrlBind) do
if m == key then
ctrlBool[i] = true
end
end
if key == "p" then
debounce = false
if switch == false and debounce == false then
switch = true
debounce = true
workspace.CurrentCamera.CameraSubject = seat
end
if switch == true and debounce == false then
switch = false
debounce = true
workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
end
end
if key == "q" then
vec = 1
end
if key == "e" then
vec = -1
end
if key == fastKey then
if not fastOn then
fastOn = true
else
fastOn = false
end
end
if key == "x" then
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, true)
on = false
seat.On.Value = on
workspace.CurrentCamera.CameraSubject = player.Character
local bool = "no"
if overridePos then
oSpeed = 1
end
overridePos = nil
end
if key == "y" then
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, false)
on = true
workspace.CurrentCamera.CameraSubject = seat
local bool = "no"
seat.On.Value = on
oSpeed = 0.2
end
if key == "h" then
if hasFTLTech(seat) then
if oSpeed == 3.3 then return end
for _, v in next, seat.Parent:GetChildren() do
if v.ClassName == "Sound" then
v:Destroy()
end
end
wait(.75)
local sound = Instance.new("Sound", seat)
sound.SoundId = "rbxassetid://1837830825"
sound.Volume = 4
sound.RollOffMaxDistance = 100
sound:Play()
local bool = "yes"
oSpeed = 3.3
end
end
end)
mouse.KeyUp:connect(function(key)
for i, m in pairs(ctrlBind) do
if m == key then
ctrlBool[i] = false
end
end
if key == "q" or key == "e" then
vec = 0
end
end)
local timeSwitch = 1
while equipped do
task.wait(.03)
updateVectors(cam,mouse,seat)
end
end
end
end)
game.ReplicatedStorage.remotes.shipStop.OnClientEvent:Connect(function(seat)
if mouseEvent then
mouseEvent:Disconnect()
mouseEvent = nil
end
if gui then
gui:Destroy()
gui = nil
end
game.ReplicatedStorage.remotes.anchorStatusShip:FireServer(seat, true)
local cam = workspace.CurrentCamera
equipped = false
cam.CameraType = "Custom"
cam.CameraSubject = player.Character.Humanoid
fastOn = false
on = false
seat.On.Value = on
workspace.CurrentCamera.CameraSubject = player.Character
local bool = "no"
if overridePos then
oSpeed = 1
end
overridePos = nil
end)
Client ^
I don’t think the code or the vehicle is the issue. It is said that the character thinks the car is part of them, so they have the same velocity as the vehicle.
This happens when the vehicle is suddenly anchored while its moving, im gonna work on the issue, nevertheless, any suggestions?
If so than in your script when you put the velocity your not detecting it properly if the player is or is NOT in the seat. wait a while Ill check the script a bit in depth
Can you elaborate more on “detecting it correctly”?
before that can you tell me where
is? I mean where it starts? cause I cant find it.
Im about as clueless as you, I have not checked that script in a long time and I just made it so it works for mobile. I’ll see what it does.
“on” is for turning on the velocity and turning it off.
yea I am clueless as well. My theory is that its just how roblox is with bodyvelocity OR OR maybe the script is not turning it off properly.
I found a solution online, its to make a render stepped loop repeating around 20 times constantly setting the velocity to 0. I’ll try it and see if it works.
It’s a really stupid part of the Roblox game engine that I think should be removed.
Anchored objects with a velocity act as a conveyor.
So you can either un anchor your cars root part or make sure the BV is set to a zero vector. Another solution you can do is turn cancollide for your car off so the player does not come into contact with your car.
Try using LinearVelocity
(you should be using this anyway because BodyVelocity
is deprecated) and see if it has the same physics issue.
Yes, I know, but as I said previously on this post, I don’t want to go through the hassle of creating a new system, there’s more work on creating a new system than fixing the problem itself.
UPDATE
I made a .stepped loop, btw, it has to be a stepped loop, not a while true do or anything, for some reason if its not .stepped it won’t work at all, but anyways, looped it about 50 times, and it worked, sometimes the character glided just a tiny bit, but overall, problem solved.