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)
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
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)
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