Could someone take a look at my flying system and see why it's doing this?

Hey everyone.
I’ve been stuck on this issue for weeks with no real solution to fixing the problem.
It has heavily blocked my progress on my current game.
DISCLAIMER: TO RECREATE THE ERROR, YOU MUST FLY THE SHIP AROUND FOR A BIT, THEN IT’LL HAPPEN AFTER A FEW SECONDS OF FLYING.

To put it short, I’ve got a flying system. It flies perfect at first (example video:)

Then, as seen in this video, it messes up and flies wrong.

Here’s the place files if someone could have a look around and figure out what’s actually going wrong.

Flying code is found in the a LocalScript in StarterPlayerScripts
PlaneSystemV3.rbxl (109.9 KB)

Raw Code:

local Speed = 50
	local Weight = workspace.Gravity*ss:GetMass()
	local Aimer = ss:WaitForChild("Aimer")

		ss.AlignPosition.Enabled = true


	local BodyForce = ss.VectorForce
	BodyForce.Force = Vector3.new(0,Weight,0) 



	while true do

		local Target = mouse.Hit
		mouse.TargetFilter = workspace


		Aimer.CFrame = Target


		ss.CFrame = CFrame.new(ss.Position, Aimer.Position)


		ss.AlignPosition.MaxVelocity = Speed


		task.wait()
	end

AlignPosition Settings:

Thanks in advanced.

Hey,

Have you tried tampering with the code that makes it move? Is there any errors, or is there anything that would change the direction of the movement?

Hey there.
Yeah I’ve been tampering with it for a few weeks now, changing and trying multiple ways and it always gives the same pretty much.

There’s zero errors, although, if you checkout the file and head to the local script which controls the Movement.
You’ll see

ss.CFrame = CFrame.lookAt(ss.Position, Target)

I believe that may be causing it, but I’ve yet to find any replacements or anything that actually works with it.

I have noticed that it happens when you spin in one direction too much

I think the problem is with the Target value

Ah I see, what do you suggest to fix it?

UPDATE:
I still believe it’s to do with

ss.CFrame = CFrame.lookAt(ss.Position, Target)

Although, I’m unsure on a replacement

you could try rotating the whole model if it makes a difference

I looked in your test place, and it looks like the angular velocity of your spaceship is going crazy, probably because your AlignPosition and VectorForce/BodyForce is shifting the spaceship around in a place that isn’t its center of mass. When I reseted the angular velocity every frame, it wasn’t shifting in direction anymore.

It’s impossible to see the angular velocity change when you are CFraming the spaceship every frame, so that’s probably why you haven’t found the problem until now.

You can just tick the ApplyAtCenterOfMass property on both the AlignPosition and VectorForce, but I would still use something to regulate the angular velocity (such as an AngularVelocity instance).

1 Like

Fixed!
PlaneSystemV3-Fixed (3).rbxl (110.3 KB)
Changed it so that the direction it goes is directly taken from the ship’s CFrame

1 Like

@goldenstein64 Hey, thanks for the information. I ticked those and so far so good. I’m using it with the combination of @OrderDestroy fix.

@OrderDestroy Hey thanks for looking into it, it has made it better however the issue did occur still. But, as seen above, with the combination of @goldenstein64, it has been solid so far. It hasn’t occured.

Hopefully it stays this way and doesn’t occur again. But thank you both, I very much appreciate it.
I was stuck on this issue for literal weeks with no solution.

With that said, Arigato, Sayonara

2 Likes