Hello!
I’ve been trying to make a realistic helicopter system, and I’m currently getting the basics of the system down. I have an issue thou. I’m using a BodyVelocity to move the helicopter up and down, but for it to move forwards, I’d like for the player to tilt the heli forward, and then it begins to move forward, like a real life heli. This is my code:
LOCAL SCRIPT
local UserInput = game:GetService("UserInputService")
local holdingdownW = false
local holdingdownS = false
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local EngVal = script.Engine.Value
local EngValCFrame = EngVal.CFrame
local EngValLastHit
local BV1 = script.Engine.Value:WaitForChild('BV1')
local BG1 = script.Engine.Value:WaitForChild('BG1')
local TurnedOn = true
local UpThrottle = true
local DownThrottle = false
local ManualControl = true
local ManualCheck = true
local RenderStepped = game:GetService('RunService').RenderStepped
RenderStepped:Connect(function()
if ManualControl == true then
BG1.CFrame = Mouse.Hit * EngValCFrame
EngValLastHit = Mouse.Hit
else
BG1.CFrame = EngValLastHit * EngValCFrame
end
end)
UserInput.InputBegan:Connect(function(input, gameprocessed)
if not gameprocessed then
--increasing speed/velocity in order to move forward using W
if input.KeyCode == Enum.KeyCode.W and TurnedOn == true and UpThrottle == false then
UpThrottle = true
while UpThrottle == true do
RenderStepped:Wait()
local x = 0.01
if BV1.Velocity.Y < 40 then
BV1.Velocity = BV1.Velocity + Vector3.new(0,0.1,0)
x = x + 0.01
else
BV1.Velocity = BV1.Velocity
end
print(BV1.Velocity.Y)
end
end
--decreasing speed/velocity in order to slow down using S
if input.KeyCode == Enum.KeyCode.S and TurnedOn == true and DownThrottle == false then
DownThrottle = true
while DownThrottle == true do
RenderStepped:Wait()
if BV1.Velocity.Y > 0 then
BV1.Velocity = BV1.Velocity - Vector3.new(0,0.1,0)
print(BV1.Velocity)
elseif BV1.Velocity.Y <= 0 then
BV1.Velocity = BV1.Velocity
print(BV1.Velocity.Y)
end
end
end
if input.UserInputType == Enum.UserInputType.MouseButton1 and ManualCheck == true then
ManualControl = not ManualControl
end
end
end)
UserInput.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.W and UpThrottle then
UpThrottle = false
end
if input.KeyCode == Enum.KeyCode.S and DownThrottle then
DownThrottle = false
end
end)
The code works as it should, and everything adds up. But when I play, and attempt to lean forward, the heli does not move forward, but instead it keeps on moving forward.
GIF
https://gyazo.com/33df016d5c92b140ac3018ff2c3709df
https://gyazo.com/33df016d5c92b140ac3018ff2c3709df
How would I use the bodyvelocity direction move forward the way the model is leaning.
Thanks!