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

How To Move Helicopter?

Asked by 5 years ago
Edited 5 years ago

Hello fellow devs. I've run into something. I wrote this script which handles moving of part perfectly like , but I don't take turning into account.

01-- Made By GooierApollo664
02-- 11/07/2019
03 
04-- Services
05local UserInputService = game:GetService("UserInputService")
06local Players = game:GetService("Players")
07 
08-- Variables
09local Heli = script.Parent.Parent
10local GyroScope = script.Parent
11local Thrust = Heli:FindFirstChild("BodyThrust")
12local Reaction = Heli:FindFirstChild("BodyReaction")
13local Force = Heli:FindFirstChild("BodyForce")
14 
15-- Physics Variables
View all 72 lines...

https://gyazo.com/3b81764428846bf1bf6ebf1d26342a7b

So I added few things to this code to make it turn using BodyAngularVelocity.

01local AngularVelocity = Heli:FindFirstChild("BodyAngularVelocity")
02 
03-- Physics Variables
04local m = Heli:GetMass()
05local g =  workspace.Gravity
06local cf = CFrame.new()
07local vector = Vector3.new()
08 
09-- Other
10local enum = Enum.KeyCode
11 
12-- Movement Table
13local Movement = {-- leaning Forward, Left, Right and back
14                  [tostring(enum.T)] = {CFrame.Angles(0, 0, math.rad(-20)), Vector3.new(0,(m*g)/27, 0)},
15                  [tostring(enum.R)] = {CFrame.Angles(math.rad(10), 0, 0), Vector3.new(0,(m*g)/67, 0)}
View all 94 lines...

https://gyazo.com/af5d7a647b6b5968c30082a264119ba2

Here I added another Table to hold nulls, that I call values which should be applied when helicopter is stopped(or no key is pressed, to be precise). The problem I have to solve, is that I should rotate Gyro based on lookVector and constantly update it, but I have trouble figuring out how to do it with this code. I came up with this solution

01function Cframe(x, z)
02 
03    if x or z then
04 
05        return CFrame.Angles(x, 0, z)
06    else
07        return CFrame.Angles(0, 0, 0)
08    end
09 
10end

this is the function I made which would replace cframe.Angles in tables.

01local Movement = {-- leaning Forward, Left, Right and back
02                  [tostring(enum.T)] = {Cframe, Vector3.new(0,(m*g)/27, 0)},
03                  [tostring(enum.R)] = {Cframe, Vector3.new(0,(m*g)/67, 0)},    
04                  [tostring(enum.Y)] = {Cframe, Vector3.new(0,(m*g)/67, 0)},
05                  [tostring(enum.G)] = {Cframe, Vector3.new(0,(m*g)/17,0)},
06                  -- Left And Right
07                  [tostring(enum.H)] = {Vector3.new(0, -2, 0), 0},
08                  [tostring(enum.F)] = {Vector3.new(0,2, 0), 0},
09                  -- Up and Down
10                  [tostring(enum.J)] = {Vector3.new(0, 100, 0), 0},
11                  [tostring(enum.LeftShift)] = {Vector3.new(0, -100, 0), 0}
12                 }
13 
14local Keys = {-- leaning Forward, Left, Right and back
15              [tostring(enum.T)] = {cf, vector},
View all 62 lines...

The problem with this is, that if I release W key or S Key, in Nulls Table first element is just CFrame.new() so passing arguments like that is not possible.

Maybe there's some methods I don't know(which there clearly are), or I'm missing something obvious. Note:I use T, R, Y, G, H, F and J keys in tables, because they are not available in studio Run test mode.

0
Can I please have a nice detailed view of the "Heli" part in explorer tab? Make sure to open all the folders, so I can see what is where. Arj783 72 — 5y
0
Idk what kind of math you have going on right now but all you have to do is use a body position and reference the main part's positing.X + a few studs and just make it move like that namespace25 594 — 5y
0
He wants it to turn, not to strafe Sir_Ragealot 72 — 4y
0
This would be a lot easier if you used modern body movers and not legacy Sir_Ragealot 72 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Maybe try an animation??

Ad

Answer this question