Skip to content

Instantly share code, notes, and snippets.

@iwacchik
Created June 6, 2023 02:28
Show Gist options
  • Save iwacchik/903258cc48bb34a2e4a8e3bd3a862e44 to your computer and use it in GitHub Desktop.
Save iwacchik/903258cc48bb34a2e4a8e3bd3a862e44 to your computer and use it in GitHub Desktop.
プレイヤーをRagdoll(ぐにゃぐにゃ状態)にするVRCワールドギミック
using UdonSharp;
using VRC.SDKBase;
using VRC.Udon.Common.Interfaces;
/// <summary>
/// プレイヤーをRagdoll(ぐにゃぐにゃ状態)にするVRCワールドギミック
/// </summary>
public class VRCRagdollSystem : UdonSharpBehaviour
{
// InteractとSetRagdollは別のスクリプトに実装することができます
public override void Interact()
{
// 自分をRagdollにする
SetRagdoll();
// ワールド内全員をRagdollにする
SendCustomNetworkEvent( NetworkEventTarget.All, nameof(SetRagdoll) );
}
public void SetRagdoll()
{
// CombatのHPが0の時にRagdollになる
Networking.LocalPlayer.CombatSetCurrentHitpoints(0);
}
public override void OnPlayerJoined(VRCPlayerApi player)
{
// Combatの初期化
// Ragdoll状態を同期させるにはローカルで全員のCombatSetupを実行する必要がある
if ( player == Networking.LocalPlayer )
{
var players = VRCPlayerApi.GetPlayers(new VRCPlayerApi[16]);
foreach (var p in players)
{
if (p == null)
{
continue;
}
p.CombatSetup();
// 画面にエフェクトが出るようになる
// デフォルト設定があるのでnullで非表示にする
p.CombatSetDamageGraphic( null );
}
}
else
{
player.CombatSetup();
player.CombatSetDamageGraphic( null );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment