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

(Answered) Jet Pack works to fly but can't move on X and Z?

Asked by 6 years ago
Edited 6 years ago

I made a jet pack which works to fly when I hold down E, but for some reason when I hold down E it works to fly up but I can't move around using the WASD or Arrow keys? It works to move around when I'm in the air only if I'm not holding down E.

01local UIS = game:GetService("UserInputService")
02local HoldingE = false
03local YVelocity = 0
04 
05UIS.InputBegan:Connect(function(inputObject)
06    if(inputObject.KeyCode == Enum.KeyCode.E)then
07        HoldingE = true
08        while HoldingE do
09    YVelocity = YVelocity + 10
10    script.Parent.JetPack.Handle.BodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
11    script.Parent.JetPack.Handle.BodyVelocity.Velocity = Vector3.new(0, YVelocity, 0)
12            wait(0.1)
13        end
14 
15    end
View all 23 lines...

I've tried removing this part of the script:

1YVelocity = YVelocity + 10
2script.Parent.JetPack.Handle.BodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
3script.Parent.JetPack.Handle.BodyVelocity.Velocity = Vector3.new(0, YVelocity, 0)
4        wait(0.1)
5    end

And when I removed that part I was able to move using the WASD and Arrow keys, so I would assume that the problem is something to do with the body velocity? (I'm New With Body Velocity)

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

The problem is that the BodyVelocity.Velocity property is trying to always set your X and Z velocity to 0.

The solution is to make it so the MaxForce property will not do anything to the X and Z values.

01local UIS = game:GetService("UserInputService")
02local HoldingE = false
03local YVelocity = 0
04 
05UIS.InputBegan:Connect(function(inputObject)
06    local handle = script.Parent.JetPack.Handle
07    if(inputObject.KeyCode == Enum.KeyCode.E)then
08        HoldingE = true
09        while HoldingE do
10    YVelocity = YVelocity + 10
11  handle.BodyVelocity.MaxForce = Vector3.new(0, 4000, 0) -- change max force
12    handle.BodyVelocity.Velocity = Vector3.new(0, YVelocity, 0)
13            wait(0.1)
14        end
15 
View all 25 lines...
1
Thank You :) kizi3000 88 — 6y
1
np! ihatecars100 502 — 6y
Ad

Answer this question