using Sandbox; public sealed class RagdollController : Component { [Group( "Setup" ), Order( -100 ), Property] public ModelPhysics bodyPhysics { get; private set; } [Group( "Setup" ), Order( -100 ), Property] public SkinnedModelRenderer bodyRenderer { get; private set; } [Group( "Config" ), Order( 0 ), Property] public bool isLocked { get; set; } public float size { get; set; } [Sync] public new bool Enabled { get => bodyPhysics.IsValid() && bodyPhysics.Enabled; set { if ( bodyPhysics.IsValid() ) { bodyPhysics.Enabled = value; bodyPhysics.MotionEnabled = value; bodyRenderer.UseAnimGraph = !value; } // Collider.Enabled = !value; if ( !value ) { // size = bodyRenderer.Parameters.GetFloat( "scale_height" ); WorldPosition = bodyRenderer.WorldPosition; bodyRenderer.LocalPosition = Vector3.Zero; // bodyRenderer.ClearParameters(); bodyRenderer.ClearPhysicsBones(); } } } protected override void OnUpdate() { if ( Network.IsOwner ) { if ( Input.Pressed( "Ragdoll" ) ) { Enabled = !Enabled; } if ( Enabled ) { // Components.GetInChildren().GameObject.WorldPosition += Vector3.Forward; bodyPhysics.WorldPosition += Vector3.Forward * Time.Delta * 100f; // GameObject.WorldPosition += Vector3.Forward; } } var bodyLock = new PhysicsLock(); bodyLock.Pitch = isLocked; bodyLock.Yaw = isLocked; bodyLock.Roll = isLocked; bodyLock.X = isLocked; bodyLock.Y = isLocked; bodyLock.Z = isLocked; bodyPhysics.Locking = bodyLock; bodyPhysics.MotionEnabled = !isLocked; WorldPosition = bodyRenderer.WorldPosition; } }