Applying velocity force to vehicle

Hello, I am trying to make a feature for my sled that when the user presses space, it makes the sled jump.

I have a separate script that sets the jump power to 0, so I don’t know if that can effect it or not.

No part in the sled is anchored, and some specific parts have welds to them.

Script:

local sled = script.Parent
local vehicleSeat = sled:FindFirstChildOfClass("VehicleSeat")

local UserInputService = game:GetService("UserInputService")

local function applyVelocity()
	if vehicleSeat then
		
		sled.Velocity = Vector3.new(0, 50, 0)
	end
end

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Space then
			applyVelocity()
		end
	end
end)

Any help is much appreciated, thanks.

velocity is depreciated you need to apply a vector force to it

1 Like

Tried that, also does not work. (assuming i didn’t mess it up)

	if vehicleSeat then
		local force = Vector3.new(0, 1000, 0) 
		sled:ApplyForce(force) 
	end
end

vectorforce is an instance, it’d be like

local attachment = Instance.new("Attachment");
attachment.Parent = sled;

local vf = Instance.new("VectorForce");
vf.Parent = sled;
vf.Force = Vector3.new(0, 50, 0);
vf.Attachment0 = attachment;
vf.ApplyAtCenterOfMass = true;
vf.Enabled = true;

Would I need to change any of the properties for the model, or does it need to be in a local script or would it work on the server?

No, you just need the attachment for the vectorforce to know where to apply the force, and if ApplyAtCenterOfMass is true then you don’t need to position the attachment

It would work on the server, on the client only if the client is the network owner of the sled

This method also does not work.

For reference, this is the code.

local sled = script.Parent
local UserInputService = game:GetService("UserInputService")

local function fireVectorForce()
	local attachment = Instance.new("Attachment")
	attachment.Parent = sled

	local vf = Instance.new("VectorForce")
	vf.Parent = sled
	vf.Force = Vector3.new(0, 50, 0)
	vf.Attachment0 = attachment
	vf.ApplyAtCenterOfMass = true
	vf.Enabled = true
end

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.R then
			local vehicleSeat = sled:FindFirstChildOfClass("VehicleSeat")
			if vehicleSeat and vehicleSeat.Occupant then
				local humanoid = vehicleSeat.Occupant.Character and vehicleSeat.Occupant.Character.Humanoid
				if humanoid then
					fireVectorForce()
				end
			end
		end
	end
end)

I’ve finally got it

local sledbody = workspace.sled.Body -- This is the main part of sled. make sure to set primary part of sled model to this
local force = sledbody.VectorForce
local vectforce = 2000 -- Change this depending on combined mass of sled and rider
local UserInputService = game:GetService("UserInputService")

local function fireVectorForce()
	force.Force = Vector3.new(0,vectforce,0)
	print('changed force +ve')
	wait(.4)
	force.Force = Vector3.new(0,0,0)
	print('removed force')
end

UserInputService.InputBegan:Connect(function(input, isProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.R then
			local vehicleSeat = sledbody.Parent:FindFirstChildOfClass("VehicleSeat")
			if vehicleSeat and vehicleSeat.Occupant then
				fireVectorForce()
			end
		end
	end
end)


If you can’t see the picture properly, i pre-added the attachment and the vector force into the free model sled im using (ignore the welds)
You don’t want to constantly keep making new forces and new attachments as the force is reusable since you can set the force to something and back