Simple helicopter movement script

This is the most important part of the local script:

--E
uis.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then
		vel.Velocity = Vector3.new(0,0,0)
	end
end)
uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then
		vel.Velocity = Vector3.new(0,10,0)
	end
end)

--Q
uis.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Q then
		vel.Velocity = Vector3.new(0,0,0)
	end
end)
uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Q then
		vel.Velocity = Vector3.new(0,-10,0)
	end
end)

--W
uis.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.W then
		vel.Velocity = Vector3.new(0,0,0)
	end
end)
uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.W then
		vel.Velocity = engine.CFrame.LookVector * 10
	end
end)

--S
uis.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.S then
		vel.Velocity = Vector3.new(0,0,0)
	end
end)
uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.S then
		vel.Velocity = engine.CFrame.LookVector * -10
	end
end)

How would i go about making A and D ones which turn the engine left and right?

Bonus points if you can point out a way to make this script more efficient and less clunky

1 Like

You are creating a separate connection for each key. I would consider that extremely inefficient. Just condense it into a single connection.

example:

uis.InputBegan:Connect(function(key)
   if key.Keycode == Enum.Keycode.S then
      --code here
   elseif key.Keycode == Enum.Keycode.W then
      --code here
   --more elseif statements here for more keys.
end)

thanks, this is really helpful!

but how could i do the A/D turning thing?

I’m a bit confused, what is vel?

Sorry, i should have clarified, vel is a BodyVelocity inside the engine.

Are you aware that bodymovers have been deprecated?

… no

But using it to move it up and down and forward and backwards works fine.
The problem is rotating the engine

I’m not exactly sure what you mean by rotating the engine. Could you attach a video or a picture for clarification?

yes, if this doesnt make sense:
E is to move the vehicle up
Q is to move the vehicle up
W is to move the vehicle forwards
S is to move the vehicle backwards
A is to turn the vehicle left
D is to turn the vehicle right

I have never worked with something like this, so its unlikely that any suggestion that I give would be very efficient or even work for that matter.
So, I will just link the documentation, which you can look through. The solution may be somewhere in there.

Link to the documentation for BodyMovers(deprecated and not suggested to be used anymore)

Link to the documentation for the BodyMovers replacement:

Have a nice day :slight_smile:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.