0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Roblox】プレイヤー同士がすり抜けるようにする

0
Last updated at Posted at 2026-02-21

はじめに

プレイヤー同士がぶつからないで、すり抜けるようにする方法です。

概要

  • PhysicsService で衝突グループを作成します
  • PhysicsService で指定した衝突グループ同士の衝突を無効化します
  • キャラクター内各パーツの CollisionGroupに、作成した衝突グループを適用します

スクリプト

ServerScriptService に Script を作成して書きます。

PhysicsService のAPIリファレンスによると
衝突グループ間の衝突関係を作成、削除、変更することはサーバー側の Script のみ可能です。

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local GROUP_NAME = "PlayersGroup"

-- キャラクター内のすべてのパーツに、衝突グループを適用
local function setCollisionGroup(character)
	for _, child in ipairs(character:GetDescendants()) do
		if child:IsA("BasePart") then
			child.CollisionGroup = GROUP_NAME
		end
	end
end

-- 対象の衝突グループが存在しなければ作成
if not PhysicsService:IsCollisionGroupRegistered(GROUP_NAME) then
	PhysicsService:RegisterCollisionGroup(GROUP_NAME)
end

-- 同じ衝突グループの衝突状態を無効化
PhysicsService:CollisionGroupSetCollidable(GROUP_NAME, GROUP_NAME, false)

-- プレイヤーがゲームに参加したときに実行
Players.PlayerAdded:Connect(function(player)
	
	-- キャラクターがスポーンしたときに実行
	player.CharacterAdded:Connect(function(character)

		-- パーツが読み込まれるのを少し待機
		task.wait(0.1)
		setCollisionGroup(character)
		
		-- 後からパーツが追加された場合にも対応
		character.DescendantAdded:Connect(function(descendant)
			if descendant:IsA("BasePart") then
				descendant.CollisionGroup = GROUP_NAME
			end
		end)
	end)
end)

参考

公式リファレンス

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?