How to remove delay in BodyGyros so that it stays constant without dampening or overshooting

Ok so im using two BodyGyros to have this arrow turret move:

Here is the code I’m using to control the two axis with gyros to have the turret follow me:

local chris = workspace.Characters:WaitForChild("chrisjd31")
local JointGyro = script.Parent.Joint.BodyGyro
local TopGyro = script.Parent.Top.BodyGyro
local JointOffsetAngle = CFrame.Angles(0,math.rad(180),0)

game:GetService("RunService").Heartbeat:Connect(function()
	JointGyro.CFrame = CFrame.new(script.Parent.Joint.Position, chris.HumanoidRootPart.Position) * JointOffsetAngle
	TopGyro.CFrame = CFrame.new(script.Parent.Top.Position, chris.HumanoidRootPart.Position)	
end)

The problem is the lag in it following me (as seen in video). What I really need is to have it stay constantly on me with out any movement lerp/delay.

Problem is that if I lower Damp (D) on the body gyro is overshoots its target and start bouncing back and forth:

How do I get the bodygyros to stay constantly on target?

Maybe you could increase the power of the bodygryo.P property in order to make it faster as it states here: BodyGyro | Documentation - Roblox Creator Hub

The problem is that its a constant juggling act between Power and Damp. If the damp is too low In proportion to the power, then you get what happens in the second video.

should be client right? not server

Yea doing from client still same result. Though doing from client does clean it up a little.

Raycasting and TweenService work with the client would possibly work

I thought of that. Just feels bad. Also Id have to do a bunch more calculations.

So instead of using BodyGyros, Im deleteing those and testing using the HingeConstaints built-in Servo function. Much more instant but still comes with a touch of jitter. Playing with it now.

OK so I found my solution. Basically I just got rid of the BodyGyros and went with the HingeConstraints Servo Actuator. Then I just calculate degrees and set this. It happens nearly instantly. Comes with a tiny bit of jitty but I figure thats ok.

For anyone who is interested, here is the HingeConstraint details:

Here is the code I used for the smoothest result:

local chris = workspace.Characters:WaitForChild("chrisjd31")

game:GetService("RunService").Heartbeat:Connect(function()
	local diff = workspace.ArrowTurret2.Joint.Position - chris.HumanoidRootPart.Position;
	local degrees = math.deg(math.atan2(diff.X,diff.Z)) ;
	if math.abs( math.abs(degrees) - math.abs( workspace.ArrowTurret2.Base.HingeConstraint.CurrentAngle ) ) > 1 then
		workspace.ArrowTurret2.Base.HingeConstraint.TargetAngle = degrees + 180
	end
end)

Here is the result:

1 Like

You could probably also play with the ServoMaxTorque and AngularSpeed to see if you can get rid of the jittering.

Yea Ill have to keep playing with it to perfect it but every combination has failed thus far. Im sure there is a sweet spot though.

Did you try making all the Parts Massless?

Yup. Tried making them massless.

Hmm I wonder if the velocity of the parts is causing it to overshoot or if thats simply the HingeConstraints servo function.

But if so, why would velocity even matter if they are massless?

Velocity affects acceleration and deceleration irl and in game, but I’m not sure what Massless does to that.
Maybe try making the Models Main Part have some mass to see if that dampens the jitters.

you don’t need physics for the movement do you? just hard cframe the dang things lol

That would be a bit too jittery dont ya think?
For example, on a moving npc:
Body gyros does nothing to movements and is pretty smooth

While cframes just destroys it’s movement and make it look like the server is taking a dump

1 Like

Draco, I do have some additional details on this matter; I’m currently making a traffic system and I do tend to agree with you here. Wrapping it up I have the server move cars per wait() and the client uses physics for the render. I discovered as I was using hinge motors and servos for the wheel rotation that the physical properties can greatly affect the movement in the physics simulation.

TLDR: @chrisjd31 I would recommend for your system to set the physics pieces CustomPhysicalProperties to true, and set them all to 0 with the exception of density at 0.01.
This should make physics look flawless