Part slides when looking at player

I am trying to make a part stare at a player, when I make it’s shape a ball it works fine, however when the part is a cube, it starts to drift onto the ground, I have considered making the square uncollideable and using an invisible ball for the hitbox, but for various reasons I need to keep it with collision on in my game, here’s the current code for it, if you know anyway to fix this, it would be greatly appreciated:

local plrs = game:GetService("Players")
local runService = game:GetService("RunService")

local looker = script.Parent.Looker
local function GetNearestPlayer()
	local lowestMag, plr = math.huge, nil
	for i, v in pairs(plrs:GetPlayers()) do
		if v.Character == nil or v.Character.PrimaryPart == nil then continue end
		local min = math.min(lowestMag, (v.Character.PrimaryPart.Position - looker.Position).Magnitude)
		if min ~= lowestMag then
			lowestMag = min
			plr = v
		end
	end
	return plr
end 

while runService.Heartbeat:Wait() do
	local nearPlr = GetNearestPlayer()
	if nearPlr == nil then continue end
	looker:PivotTo(CFrame.new(looker.Position, nearPlr.Character.PrimaryPart.Position))
end
1 Like

try setting the assemblylinearvelocity of the cube to Vector3.zero in the heartbeat event, or you could redo this system using alignorientation and alignposition to keep it in place

The first option seems to work decently well, it still does slide a bit and seems to shake somewhat, I’ll use it for now temporarily and see if I can figure out how to use alignorientation and alignposition since I lack experience in those fields, thanks.

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