BodyConstraints - Rigid movement?

I’m working on a flight system as linked below - I currently have a bumpy / rigid effect when trying to fly behind the Player.
https://gyazo.com/96157a2c6530bbf393536073792d7547

I initially thought that using Mouse.Hit.p was the issue so I remade it using UserInputService and converting 2D to 3D. However the issue still occurs when attempting to fly behind.
Does anyone have any suggestions? I’m looking for it to just rotate accordingly and smoothly.

	function Core:LookAt(Base, ...)
		Base = self.Base
		
		local MousePos = Core:GetMousePos(...)
		local OriginCF = self.AlignOrientation.CFrame
		local Size = Base.Size
		
		local Target = Base.Position + ((MousePos - Base.Position).unit * 100)
		local Dir = (Target - Base.Position).unit
		local SpawnPos = Base.Position
		
		local Left = Base.CFrame * CFrame.new(-Size.X / 2, 0, 0).Position
		local Right = Base.CFrame * CFrame.new(Size.X / 2, 0, 0).Position
		local Mid = (Target - Base.Position).Magnitude
		
		local Foebmd = Base.CFrame * CFrame.new(0, 0, -Mid).Position
		local ToLeft = (Target -Left).Magnitude
		local ToRight = (Target -Right).Magnitude
		local Rot = ((Foebmd - Target).Magnitude / 10)
		
		local Pos = SpawnPos + (Dir * 1)
		local Turn = math.rad((Rot / 10) * 40)
		if Turn > math.rad(89) then
			Turn = math.rad(89)
		end
		
		if ToLeft < ToRight and ToLeft > Rot then
			self.AlignOrientation.CFrame = CFrame.new(Pos, Pos + Dir) * CFrame.fromEulerAnglesXYZ(0, 0, Turn)
		elseif ToLeft > ToRight and ToRight > Rot then
			self.AlignOrientation.CFrame = CFrame.new(Pos, Pos + Dir) * CFrame.fromEulerAnglesXYZ(0, 0, -Turn)
		else
			self.AlignOrientation.CFrame = CFrame.new(Pos, Pos + Dir)
		end
	end

Im as confused as you are, the code looks alright.

I would recommend simplifying the code to narrow down and find problem. Also adding a debug parts to visualize the CFrame.

I suspect it is either the turn CFrame doing something weird, or the dir direction.

Start by removing the turn variable and also setting the align orientation to rigid.

Theoretical if the CFrame is correct and the body mover is rigid it will always point towards the mouse.

1 Like

Is it possible that mouse.hit is hitting the player/aircraft itself?

2 Likes

I’ve removed the turn and it still applies.
I’m unsure if it’s to do with the code dictating left / right direction?

Initially I thought so to however I changed it to use UIS where it casts a ray from the Camera 1000 studs and doesn’t technically register the models?

		local Camera = Server:GetService('Workspace'):WaitForChild('Camera', 1)
		
		local MouseScreenPointPos = game:GetService("UserInputService"):GetMouseLocation()
		local ViewportMouseRay = Camera:ViewportPointToRay(MouseScreenPointPos.X, MouseScreenPointPos.Y)
		
		return ViewportMouseRay.Origin + ViewportMouseRay.Direction * 1000