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

Trying to change the body velocity of a player after pressing a certain key?

Asked by 4 years ago

I'm trying to change the body velocity of the player after they press a certain key. Ideally, I wanted it so after the player pressed a certain key they world be flung upwards and then flung downwards back to the ground. Here is my failed attempt.

01adebounce = false
02local UIS = game:GetService("UserInputService")
03local char = script.Parent
04local jumpshiftanim = Instance.new("Animation")
05jumpshiftanim.AnimationId = "rbxassetid://example"
06 
07local keybind = Enum.KeyCode.LeftShift
08local canjump = true
09 
10UIS.InputBegan:Connect(function(input,gameprocessed)
11    if gameprocessed then return end
12    if not canjump then return end
13 
14    if input.KeyCode == keybind then
15        canjump = false
View all 38 lines...

1 answer

Log in to vote
1
Answered by 4 years ago

Thing is, you're using .Velocity wrong. .Velocity determines the target velocity towards which force will be exerted.

See this to know more: https://developer.roblox.com/en-us/api-reference/class/BodyVelocity

So here's how I would go about exerting BodyVelocity to my character...

01local char = script.Parent
02 
03local jump = Instance.new("BodyVelocity")
04jump.MaxForce = Vector3.new(1000,1000,1000) --Maximum force to be exerted in each axis
05jump.Velocity = char.HumanoidRootPart.CFrame.UpVector * 1000 --exerts 1000 upwards
06jump.Parent = char.HumanoidRootPart
07 
08wait(1)
09 
10jump.Velocity = char.HumanoidRootPart.CFrame.UpVector * -10000 --now flings them backward
Ad

Answer this question