I can't get AlignPosition to work for my Plane

I’ve made a few topics on this, but I have not gotten my AlignPosition issues settled.

Basically, I created a plane system using the old BodyMovers, however, they would cause issues when I would change the NetworkOwnerShip of them, or at least I think that is the case (since they are depreciated and have been for a long time), as seen in this post.

I got LinearVelocity to work, as it was just a simple conversion from BodyVelocity to LinearVelocity with very little change to my code. However, when switching over to AlignOrientation from BodyGyro, I have failed to get the results I wanted. All that will happen, is the plane will start up, and then start to rotate violently before the impact detection system built into the planes blows it up.

You can see how horrific it is here. No errors show up in output, making this even more frustrating.

I am not sure what I am doing wrong. Here is the LocalScript code for handling the plane movement, using LinearVelocity and AlignOrientation:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local val = script:WaitForChild("plane")
local connection = val.Value
local USINS=game:getService("UserInputService")
local engine = connection:WaitForChild("Engine")
local gyro = engine:WaitForChild("AlignOrientation")
local velo = engine:WaitForChild("LinearVelocity")
local clickMove = false

local function GetBankAngle(M) --This function calculates the Bank Angle
	local VSX,X = M.ViewSizeX,M.X
	local Ratio = (((VSX/2) - X)/(VSX/2))
	Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
	return math.rad(Ratio * 80)
end
local function SetAlignOrientationCFrame(alignOrientation, cframe)
	alignOrientation.PrimaryAxis = cframe.RightVector
	alignOrientation.SecondaryAxis = cframe.UpVector
end

if connection ~= nil then
	game["Run Service"].RenderStepped:Connect(function(step)		
		if not USINS:GetFocusedTextBox() then
			Mouse.TargetFilter = game.Workspace
			local BankAngle = GetBankAngle(Mouse)
			if clickMove then
				SetAlignOrientationCFrame(gyro,((LastHit or Mouse.Hit)*CFrame.Angles(0,0,BankAngle)))
			else
				SetAlignOrientationCFrame(gyro,(Mouse.Hit*CFrame.Angles(0,0,BankAngle)))
			end
			velo.VectorVelocity = (engine.CFrame.lookVector)*values.currSpeed.Value
		end
	end)
end

When compared to the old script, it is almost the same:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local val = script:WaitForChild("plane")
local connection = val.Value
local USINS=game:getService("UserInputService")
local engine = connection:WaitForChild("Engine")
local gyro = engine:WaitForChild("BodyGyro")
local velo = engine:WaitForChild("BodyVelocity")
local clickMove = false

function GetBankAngle(M) --This function calculates the Bank Angle
	local VSX,X = M.ViewSizeX,M.X
	local Ratio = (((VSX/2) - X)/(VSX/2))
	Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
	return math.rad(Ratio * 80)
end

if connection ~= nil then
	game["Run Service"].RenderStepped:Connect(function(step)		
		if velo.MaxForce == Vector3.new(math.huge,math.huge,math.huge) and not USINS:GetFocusedTextBox() then
			Mouse.TargetFilter = game.Workspace
			local BankAngle = GetBankAngle(Mouse)
			--gyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
			--velo.maxForce = Vector3.new(math.huge,math.huge,math.huge)
			if clickMove then
				gyro.cframe = ((LastHit or Mouse.Hit)*CFrame.Angles(0,0,BankAngle))
			else
				gyro.cframe = (Mouse.Hit*CFrame.Angles(0,0,BankAngle))
			end
			velo.velocity = (engine.CFrame.lookVector)*values.currSpeed.Value
		end	
	end)
end

I’m sort of at my wit’s end for this, and this plane system is super important for my current and future games, so I would appreciate some help with this.

1 Like

Why don’t you edit AlignOrientation.CFrame instead of Primary/SecondaryAxis?

1 Like

I have tried that as well, and the same occurrence happens where the plane spins uncontrollably until it blows up.

What are the settings of your align orientation?

1 Like

Here are my settings:
https://gyazo.com/6e0acdd42a85e6274e9842b9120224c7

Try enabling PrimaryAxisOnly. It might not work but let’s see if it stops the issue.

Does not stop the issue. It continues to flip out, albeit not as violently as before, as you can see here:
https://gyazo.com/146af79a5bf7ed846b5f7422a0ae1954

1 Like

More of it just spinning https://gyazo.com/b389dc0902df6ef82efc8e5b59816812

1 Like

Can you send a minimal place file of the plane or something that uses this setup? It might help us solve the issue.

1 Like

brokenPlane.rbxl (159.1 KB)

There it is.

After studying the repro file, I first noticed the CFrame was being sent over, using a remote. I removed that functionality since it works fine from the client.

Secondly, I noticed the attachment is WAY offset. I made the attachment at the center of mass.

Finally, I noticed that for whatever reason it doesn’t work unless you use RidgityEnabled.

fixed Place:
brokenPlane.rbxl (159.2 KB)

also what is the hair on the regen part for?

3 Likes

That is the solution. Only issue is, AlignPosition makes the movement of the plane’s angles not very natural, as seen here: https://gyazo.com/e79020bd2b61719c18e23fc7c5bd0d43

Here is how the plane should be more natural, using BodyGyro:
https://gyazo.com/73342d33e7ce0266e1008dfa27256100

For the time being I may just use LinearVelocity and BodyGyro together

You can also tween the CFrame of the align position if you wish.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.