Help with helicopter calculation

Hi!!
I am quite new to vehicle development,
I tried with a simple script.
Keys are basically a table containing keys are pressed, if keys are pressed it returns true (ignore it xd)
I think you should understand this

local function fly()
			
			Xrotation = Xrotation == -0.2 and 0.2 or Xrotation == 0.2 and -0.2
			ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position)
			if Keys.E then
				ExpectedSpeed = Vector3.new(ExpectedSpeed.X,math.clamp(Force.Velocity.Y + 1,1/math.pi,15),ExpectedSpeed.Z)
				local xD = 0
				
			
				print(Xrotation)
				if tick() - lastT > 0.2 then
					lastT = tick()
					ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position) * CFrame.Angles(math.rad(Xrotation),0,math.rad(Xrotation))
				end
				
			else
				ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position)
				ExpectedSpeed = Vector3.new(ExpectedSpeed.X,math.sin(tick()),ExpectedSpeed.Z)
			end
			if Keys.W then
				
				
				Speed = math.clamp(Speed + 0.1,0,120 --[[maxspeed]])
				local yes = Mainpart.CFrame.LookVector.Unit * Speed
				ExpectedSpeed = Vector3.new(yes.X,ExpectedSpeed.Y,yes.Z)
				ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position) * CFrame.Angles(math.rad(-10),0,0)
			else
		
				ExpectedSpeed = Vector3.new(0,ExpectedSpeed.Y,0)
			end
			if Keys.A then
				local yes = Mainpart.CFrame.RightVector.Unit * Speed
				--ExpectedSpeed = Vector3.new(-yes.X,ExpectedSpeed.Y,-yes.Z)
				Athingy += 0.5
				ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position) * CFrame.Angles(0,math.rad(Athingy),math.rad(12))
			end
			Gyro.CFrame = ExpectedGyroCFrame
			game:GetService('TweenService'):Create(Force,TweenInfo.new(0.6),{Velocity = ExpectedSpeed}):Play()
		--	Force.Velocity = ExpectedSpeed
		end

Sorry for long code, it might be annoying to check it out.
The only trouble is at the ExpectGyroCFrame.

The trouble, is clearly.

It will make a new CFrame basing on the Position, which will always look to the front (look back to the fron always)
I want it to rotate.
But without going back to the front,
Any idea on how can I fix this?
The way it should rotate, must be X,Y,Z axis, for effects like spinning, and going forward

Gif of error: https://gyazo.com/3c99c51d7fa962d615c8441315b7c020

now, I know error, why can’t I fix it?
Because I don’t really know what to do.


The helicopter should rotate according to the look vector of it.


So, it should rotate, and than go back (when no key is pressed)
To a CFRAME according to ITS LOCAL ORIENTATION but, without rotation, I think you know what I mean, sorry for post to long.

epic 3D draws :sunglasses::ok_hand:

1 Like

I believe your already found the problem since:

This new CFrame will default to looking at the world “front” like in the gif if printed out it’ll be like:

Position , 1, 0, 0, 0, 1, 0, 0, 0, 1

I recommend instead of continually creating a new CFrame you manipulate the current Helicopter’s CFrame through CFrame multiplication like so:

Helicopter.CFrame = Helicopter.CFrame * RotationCFrame

Yeah, but this would make the helicopter spin a lot, or be available to do 360 spins

Have you tried a physics solution or a combination of both CFrame and the new VectorForce?

I don’t like vectorforce, I don’t need it since the trouble here it’s when it rotates (it rotates back to front)
I want to rotate it basing where it’s facing at (but without orientation,only the rotating orientation (X Axis) that makes spin the chopper)
Any idea?

Well then you would need to modify the CFrame.new which is making your helicopter facing the front

			ExpectedGyroCFrame = CFrame.new(Mainpart.CFrame.Position)

You would do this by using CFrame. from matrix like so:

local upUnit = Vector3.Unit(0,1,0)
ExpectedGyroCFrame = CFrame.fromMatrix(Mainpart.CFrame.Position,Mainpart.CFrame.RightVector,upUnit)

This should make it keep the direction of where the helicopter is facing through reusing the:

Mainpart.CFrame.RightVector

while making the helicopter upright in the upUnit

Thanks, it seems it worked
Now I will go on fixing this xD
https://gyazo.com/3c2139fff20ca3c029750cd60cde348a