How do I prevent odd jittering when the a constantly oriented object gets offset, idk

Jittering UFO

As you can see, there is a ufo, and it is constantly twitching and jumping up and down. Is there a way to detect this with server scripts? The ufo is constantly being oriented upright to act as a gyro, and I think that’s the issue. But when I detect if its going fast, it doesn’t give the desired results. (its being oriented on heartbeat) This is seriously annoying, and ruins the gameplay. it sometimes jitters via turning as well, so that would be nice to detect.

2 Likes

use alignorientation to adjust its orientation so its physics based

Going to assume that you’re orienting the UFO with code, could you show us the code?

If you’re willing to consider @BanishAlt’s recommendation, an AlignOrientation can easily do the job for you.

Y-AXIS

AlignOrientation can align an object, like in this case your UFO, towards specific axes. To insert one, do this (in order):

  • insert an attachment on your UFO
  • insert AlignOrientation, set Mode to OneAttachment
  • set Attachment0 to your UFO’s attachment

AlignOrientation has a property called SecondaryAxis which (on default) makes it face towards the sky or Vector3.new(0, 1, 0)

ROTATION

Now if you’ll notice, it also has a property called PrimaryAxis which (on default) makes it face forwards or Vector3.new(1, 0, 0)

AlignOrientation actually has a CFrame property – this is what dictates what PrimaryAxis sees as “forward”.

Assuming that your vehicle has turning code for WASD, you can apply similar logic and change the AlignOrientation’s CFrame rotation.

This is the code I use to orient the ufo. Its quite simple

Model = script.Parent.Parent.Parent --the ufo <
game:GetService('RunService').Heartbeat:Connect(function()
			local AngleZ = -Model.PrimaryPart.Orientation.Z
			local AngleX = -Model.PrimaryPart.Orientation.X
			Model:PivotTo(Model:GetPivot() * CFrame.Angles(math.rad(AngleX), 0, math.rad(AngleZ)))
end)

--the hover script \/, if it helps

ame:GetService('RunService').Heartbeat:Connect(function()
	script.Parent.CanCollide = true
	local Parts = game.Workspace:GetPartsInPart(script.Parent)
	script.Parent.CanCollide = false
	if isEmpty(Parts) then
		script.Parent.AssemblyLinearVelocity = Vector3.new(0,-10,0)
	else
		if #Parts == 1 then
			local Part
			for index, child in pairs(Parts) do
				if child.Name == "SpawnBox" then
					script.Parent.AssemblyLinearVelocity = Vector3.new(0,-3,0)
				else
					if child.Parent.Parent == script.Parent.Parent.Parent then script.Parent.AssemblyLinearVelocity = Vector3.new(0,-3,0) else
						script.Parent.AssemblyLinearVelocity = Vector3.new(0,10,0)
					end
				end
			end
		else
			script.Parent.AssemblyLinearVelocity = Vector3.new(0,10,0)
		end
	end
	for index, child in pairs(Parts) do
		if child.Anchored == false then
			for i = 1,20 do
				task.wait()
				child.AssemblyLinearVelocity = Vector3.new(0,50,0)
			end
		end
	end
end)

function isEmpty(t)
	for i, v in t do
		return false
	end
	return true
end

I dont see how I could really fix this, and wether its the hover or the gyro script for sure. would align orientation really fix it? if so, can you tell me whats better about it than what I did?

1 Like

Could you send me the UFO model so that this code could work?

Ufo.rbxm (370.5 KB)

Just so you know, its destructible.

i just checked the code, and yeah i can see how it was breaking now
(im working on rewriting it)

Ufo2.rbxm (372.6 KB)
Done, (there might be some drift issues but like it should work better)

All it really did was add drift and get rid of the abduction function. And the jittering is still there. What did the align orientation do?

i did not know there was an abduction function in the hover script
anyway the align orientation kept it from smacking into stuff, so you could just keep that and see if it works

I generally just want a way to detect it, the glitching only happens if you get hit hard, so it won’t be often, my solution was to disable the scripts that make you hover and stay upright and you fall, and re stabilize. but I can’t detect it. is there a way to do that?

i guess if the X and Z orientations are too far from the default 0 then flip them around for the vehicle seat

Currently trying to implement this.

This didn’t seem to do anything, I think the reason is the hover script applying velocity. It somehow lags and adds extra velocity when you get hit hard, or some other reason layers it somehow, so I think what I need to do is limit the velocity.

So apparently the glitching was because the vehicle seat’s velocity somehow glitching out. im constantly changing the model’s velocity, so maybe something with the player is making it weird. either way, I got it reduced to minor vibrations that sometimes stop. and only start after a time of destruction. thanks for the help though =)

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