Plane Movement Question

I have a functional plane, however the gyro faces mouse.Hit and it can not fly “upside down” and will spasm when trying to do a looping or fly below 90 or -90 degrees.
How do I script this so I can make the plane loop, fly upside down, etc.?

Do you use crazyman32’s planekit, or a custom made one?

I script myself, I just don’t know what to use to script the movement.
It’s not about the lua, it’s about the logic?

1 Like

I ran into the same problem which results from the way CFrames work. My alternative was to just get the distance the mouse is from the center of the screen and rotate the gyro by those numbers. BTW, I did some curving so that the distance from center to turn ratio isn’t linear.

Can I have that code snippet?
Would be very nice, thanks!

Yes, this is a simplified version of what I did:

tilt =  ((((Mouse.ViewSizeY/2)-Mouse.Y)))/2000
bank = ((((Mouse.ViewSizeX/2)-Mouse.X)))/2000 
self.BodyGyro.CFrame = self.BodyGyro.CFrame * CFrame.Angles(math.rad(tilt * self.CurrentShip.TurnSpeed),math.rad(bank * self.CurrentShip.TurnSpeed),0)
3 Likes

What do those 2000’s represent and what is your TurnSpeed setting?

The 2000 is basically the damping on the distance of the mouse movement so that the turning. That number isn’t even needed if you just make the turn speed really small and you can get the turn speed by tuning it a lot.

This is the code I use for my helicopters so that they point towards the mouse. Hopefully this will prove of use to you.

local TargetPosition = Mouse.Hit.p
			
local origincframe = BodyGyro.CFrame
local size = Engine.Size
		
local target = Engine.Position+((TargetPosition - Engine.Position).unit*100)
local dir = (target - Engine.Position).unit
local spawnPos = Engine.Position
local left = Engine.CFrame*CFrame.new(-size.x/1, 0, 0).p
local right = Engine.CFrame*CFrame.new(size.x/1, 0, 0).p
local md = (target - Engine.Position).magnitude
		
local foebmd = Engine.CFrame*CFrame.new(0, 0, -md).p
local toleft = (target -left).magnitude
local toright = (target -right).magnitude
local toeven = 99.95
			
local rot = ((foebmd - target).magnitude/(5*10))
if toleft >= toeven and toright >= toeven then
	rot = math.huge
end
			
local pos = spawnPos + (dir * 1)
HelicopterGyro.MaxTorque = Vector3.new(9000, 9000, 9000)
if toleft< toright and toleft >rot then
	HelicopterGyro.CFrame = CFrame.new(pos,  pos + dir)*CFrame.fromAxisAngle( Vector3.new(0, 0, rot) , math.pi/ 40 )
elseif toleft > toright and toright >rot then
	HelicopterGyro.CFrame = CFrame.new(pos,  pos + dir)*CFrame.fromAxisAngle( Vector3.new(0, 0,-rot) , math.pi/ 40 )
else
	HelicopterGyro.CFrame = CFrame.new(pos,  pos + dir)
end
1 Like