I have a union that is supposed to follow the mouse’s position but after moving to the desired position set in the BodyPosition it sometimes jitters.
Inside the union I have a BodyPosition and a BodyGyro. The BodyGyro is meant to maintain the union’s orientation. Its CFrame is modified and is set to: CFrame.Angles(0, 0, math.rad(-90)). Here are the properties of the BodyPosition and the BodyGyro and a few scripts, as well as a clip that shows my problem.
BodyGyro properties:
D = 500
MaxTorque = 400000, 400000, 400000
P = 3000
BodyPosition properties:
D = 250
MaxForce = 40000, 40000, 40000
P = 10000
Position = 10, 0.5, 0
When the player joins the game I set the player as the network owner of the union (named “Striker”). I need to do this because the striker’s movement must be replicated to the server. I am still unsure of exactly what “SetNetworkOwner” does.
game.Players.PlayerAdded:Connect(function(plr)
workspace.Striker:SetNetworkOwner(plr)
end)
(Server Script located in ServerScriptService)
Then, a local script in StarterPlayerScripts will repeatedly get the player’s mouse and get it’s CFrame position. That position is then set to the striker’s BodyPosition so that the striker moves to the mouse’s position.
local runService = game:GetService("RunService")
local mouse = game.Players.LocalPlayer:GetMouse()
local striker = workspace.Striker
runService.RenderStepped:Connect(function()
local mousePos = mouse.Hit.p
local pos = mousePos
striker.BodyPosition.Position = Vector3.new(pos.X, striker.BodyPosition.Position.Y, pos.Z)
end)
(Local Script located in StarterPlayer.StarterPlayerScripts)
The movement of the striker works, but as mentioned earlier, the striker jitters when it moves to the target. Here is a video that shows this jittering motion.
I hope you can help me find the solution to my problem. Thanks in advance.