Hi, I’m trying to make a Plane. I wrote some code. The only thing my plane can do is turn left and right. It can also accelerate back and forth. (I used Body Velocity for acceleration, and BodyAngularVelocity for rotation). All I have to do is make it fly in the direction my mouse is looking. But how do I do this?? I tried to use many ways, but all it led to was just the bugs and lags. Please, can someone help me implement this? (You don’t have to write all the code on plane, just tell me how to make it fly where my mouse is looking.)
As far as i know, you need to get Mouse.Hit.Position
and use your head Position
and use unit
to do that. I never made planes but i think it’d work like this:
direction = (Mouse.Hit.Position - Character.Head.Position).unit
I’ll try it, thanks. (you don’t know what exactly I should do with this value? I mean, where do I apply it? in the orientation, or angular velocity?)
Maybe both, for movement and rotation
You could try to use a BodyGyro instead, feeding it the direction you want it to face (maybe you’ll have to get the angles from the direction vector but it’s not hard). You can get the direction the way Andr_yy said.
Don’t discard BodyAngularVelocity though, as you may want to use it in the future for rolls and stuff
Everything seems to be working, but my plane is behaving strangely. how can I fix this? I use 1 line of code to change the rotation of the plane.
local Direction = (Mouse.Hit.Position - Character.Head.Position).unit
-----------
BodyAngularVelocity.AngularVelocity = Direction
Uh oh. Try using BodyGyro
s for that
how do I get it to rotate using the gyro body? I should use bodygyro.cframe = cframe.new (pos, direction) but what should I use as “pos”?
Not experienced with CFrame
, but try putting any positions in there (model’s, head’s etc)
I probably won’t answer soon, since I’ll have to learn body gyro and cframe. But I’ll answer when I can
local Direction = (Mouse.Hit.Position - Character.Head.Position).unit
BodyGyro.CFrame = CFrame.Angles(Direction)
Argument 3 missing or nil
Why i have this error?
CFrame.Angles takes 3 arguments, but you’re only giving one.
But my Direction is a three-digit value: 0.29635337, 0.864617527, 0.405723006. How do I make it work?
Try doing:
BodyGyro.CFrame = CFrame.Angles(0.29635337, 0.864617527, 0.405723006)
I forgot to say, this is the value of my mouse, and it always changes. (I pass it via remote function) trying to write a 3 value in parentheses results in: Unable to cast Vector3 to float
I also thought so at first, but it works even when I don’t click.
local Direction = (Mouse.Hit.Position - Character.Head.Position).unit
BodyGyro.CFrame = CFrame.Angles(Direction)
Argument 3 missing or nil
How do I fix this?
You have to unpack the components of the Direction
vector.
BodyGyro.CFrame = CFrame.fromOrientation(Direction.X, Direction.Y, Direction.Z)
Or better yet:
BodyGyro.CFrame = CFrame.new(Vector3.new(0, 0, 0), Direction)
Thanks, it worked, but it didn’t solve my problem with flying There have a video above about how my plane flies, the problem has been solved a little, but mostly everything remains as it was. How do I make my plane turn a little slower and more correctly? (My plane is twitching strangely)