Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Body Velocity not working as expected?

Asked by 3 years ago
Edited 3 years ago

So ive been trying my hand at a vehicle, and so far its been going pretty good. However this is one thing that does not make any sense to me. I thought it would be a good idea to use a Body Velocity to move my vehicle (I'm really not make anything that advanced here), but no matter what value I use for the Velocity property of Body Velocity, the part I'm using simply goes in the same direction.

VehicleEvent.OnServerEvent:Connect(function(plr, Type, Motion)
    local CurrentBV = nil
    warn("Player Input Type:", Type, Motion)
    Vehicle.Anchored = false
    if Type == "InputBegan" then
        if Motion == "Forward" then
            ForwardHold = true
            CurrentBV = MoveVehicle(CFrame.new(0,0,-10), 10, CurrentBV)
            print(CurrentBV)
        end
        if Motion == "Left" then
            LeftHold = true
            CurrentBV = MoveVehicle(CFrame.new(-10,0,0), 10, CurrentBV)
            print(CurrentBV)
        end
        if Motion == "Backward" then
            BackwardHold = true
            CurrentBV = MoveVehicle(CFrame.new(0,0,10), 10, CurrentBV)
            print(CurrentBV)
        end
        if Motion == "Right" then
            RightHold = true
            CurrentBV = MoveVehicle(CFrame.new(10,0,0), 10, CurrentBV)
            print(CurrentBV)
        end
    else

Inside the function:

local MoveVehicle = function(MoveTo, P, CurrentBV)

    if CurrentBV ~= nil then
        CurrentBV:Destroy()
    end

    local BV = Instance.new("BodyVelocity",Vehicle)
    BV.Velocity = (Vehicle.CFrame * MoveTo).Position
    BV.P = P
    BV.MaxForce = Vector3.new(100000,100000,100000)
    Instance.new("Part",game.Workspace).Position = (Vehicle.CFrame * MoveTo).Position
    return BV
end

Is there a problem with my code, or have I completely misunderstood Body Velocity

Answer this question