Make two players look at each other at all times [2D Fighting Game]

Hello, let me get straight to the point:

I had previously solved this issue but when I try replicated the exact same code and workspace environment to another place (Roblox definition), it produces a weird side effect.

For example:

Weird One


(The yellow boxes are non can-collide and are massless)

Normal One

This is the code btw:

local Player: Player = game.Players.LocalPlayer
local Character: Model = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart: BasePart = Character:WaitForChild('HumanoidRootPart')
local CurrentCamera: Camera = workspace.CurrentCamera

local RunService = game:GetService("RunService")
local PlayerService = game:GetService("Players")


-- Wait until there are 2 players in the game.

repeat wait() until #PlayerService:GetPlayers() >= 2

-- Set the camera to 'Scriptable'

CurrentCamera.CameraType = Enum.CameraType.Scriptable

-- Find the other player

local Enemy: Player

for _, players: Player in pairs(PlayerService:GetPlayers()) do
	if players.Name ~= Player.Name then
		Enemy = players
		break
	end
end

local EnemyChar: Model = Enemy.Character or Enemy.CharacterAdded:Wait()
local EnemyHRP: BasePart = EnemyChar:WaitForChild('HumanoidRootPart')



-- Function to change player direction.

function UpdateLookDirection()

	local TargetPos = EnemyHRP.Position
	local Direction = (TargetPos - HumanoidRootPart.Position).Unit
	local Angle = math.atan2(Direction.X, Direction.Z)

	Angle += math.pi

	HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0,Angle,0)
	
end


RunService.RenderStepped:Connect(UpdateLookDirection)

Please help, I genuinely don’t know how this could actually happen. The code is the same on both games.

1 Like

I believe there is a setting in roblox studio that makes it so that players don’t collide with eachother, because even though the Hitboxes don’t have CanCollide, the player model still has collisions with other players.

Hello, thanks for responding. And what might that setting be?

You can use Collusion Groups for this.