Stop models from deforming when PivotTo is called on the model and its parent?

I’ve been having an issue with a script I have that moves a joystick which is on a moving platform. When both the platform and the joystick have PivotTo() called on them (causing the joystick to move twice) the joystick begins deforming itself. Here’s an image when the game first starts:
image
and here’s an image of the joystick after the platform and itself have moved:
image
Finally: Here’s an image from after the platform has been sent back and forth numerous times:
image

Here’s the code:

function manageJoystick(dt,pos:Vector2)
	local joystick = hVeh.Controls.Joystick
	joystick.Stick:PivotTo(joystick.Joint.CFrame * CFrame.Angles(0,math.rad(pos.X)*30,math.rad(pos.Y)*30))
end

function moveCrane(dt,pos:Vector2)
	x += dt * speed * pos.Y
	z += dt * speed * -pos.X
	
	veh:PivotTo(origin * CFrame.new(0,0,x))
	hVeh:PivotTo(veh.PrimaryPart.CFrame * HCarriageOffset * CFrame.new(z,0,0))
	
	
end

connection = rs.Heartbeat:Connect(function(dt)
	local F = uis:IsKeyDown(Enum.KeyCode.Up)
	local B = uis:IsKeyDown(Enum.KeyCode.Down)
	local L = uis:IsKeyDown(Enum.KeyCode.Left)
	local R = uis:IsKeyDown(Enum.KeyCode.Right)
	
	local inp = Vector2.new((R and 1 or 0) - (L and 1 or 0), (F and 1 or 0) - (B and 1 or 0))

	pos = ((pos - inp)/1.1)+inp
	
	moveCrane(dt,pos)
	manageJoystick(dt,pos)
	
end)

My best assumption of what is happening here is some sort of floating-point error, but I’m not entirely sure. If anyone knows how this could be fixed, let me know!
Thanks

Try using a Motor6D to connect the joystick to the base.
You can modify the C0 or C1 property to move the joystick and it stays welded to the base.

You could also just use Constriaints which use physics instead of PivotTo for moving the crane and cab around .

1 Like

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