2024-10-30 13:15:49 +03:00
|
|
|
using Sandbox.Utils;
|
|
|
|
public sealed class RagdollController : Component
|
|
|
|
{
|
|
|
|
[Group("Setup"), Order(-100), Property] public ModelPhysics bodyPhysics { get; set; }
|
|
|
|
[Group("Setup"), Order(-100), Property] public SkinnedModelRenderer bodyRenderer { get; set; }
|
|
|
|
|
|
|
|
[Group("Config"), Order(0), Property, Range(0, 15)] public int impaledPhysicsBodyIndex { get; set; }
|
|
|
|
[Group("Config"), Order(0), Property] public bool isLocked { get; set; }
|
|
|
|
[Group("Runtime"), Order(100), Property] public PhysicsBody impaledPhysicsBody { get; set; }
|
|
|
|
|
|
|
|
// Sensible Indexes
|
|
|
|
// 3 - HEad
|
|
|
|
|
2024-10-30 13:33:29 +03:00
|
|
|
[Sync]
|
|
|
|
private bool Enabled
|
2024-10-30 13:15:49 +03:00
|
|
|
{
|
2024-10-30 13:33:29 +03:00
|
|
|
get => bodyPhysics.Enabled;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Log.Info(value);
|
|
|
|
bodyPhysics.Enabled = value;
|
|
|
|
bodyPhysics.MotionEnabled = value;
|
|
|
|
bodyRenderer.UseAnimGraph = !value;
|
|
|
|
}
|
2024-10-30 13:15:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateBody()
|
|
|
|
{
|
|
|
|
//impaledPhysicsBodyIndexRemapped = GetClosestSafeIndex(impaledPhysicsBodyIndex);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (isLocked)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bodyPhysics.Enabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
impaledPhysicsBody = bodyPhysics.PhysicsGroup.Bodies.ElementAt(impaledPhysicsBodyIndex);
|
|
|
|
|
|
|
|
var followToPos = GameObject.Transform.World.Position;// - (GameObject.Transform.World.Forward * 30.0f);
|
|
|
|
|
|
|
|
// If this was
|
|
|
|
if (impaledPhysicsBodyIndex == Bones.Terry.spine_0)
|
|
|
|
{
|
|
|
|
followToPos += Vector3.Up * 10.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
//hitPhysicsBody.Position = followToPos;
|
|
|
|
var delta = Vector3.Direction(impaledPhysicsBody.Position, followToPos);
|
|
|
|
|
|
|
|
impaledPhysicsBody.Velocity = delta * 500.0f;
|
|
|
|
//impaledPhysicsBody.Velocity = Vector3.Zero;
|
|
|
|
//impaledPhysicsBody.Position = MathY.MoveTowards(impaledPhysicsBody.Position, followToPos, Time.Delta * 100.0f);
|
|
|
|
//Log.Info($"delta.Length: {delta.Length}, impaledByHarpoonSpear.isInFlight: {impaledByHarpoonSpear.isInFlight}");
|
|
|
|
|
|
|
|
bool useOriginalMethod = true;
|
|
|
|
if (useOriginalMethod) //delta.Length < 15.0f)// && !impaledByHarpoonSpear.isInFlight)
|
|
|
|
{
|
|
|
|
impaledPhysicsBody.Velocity = delta * 1000.0f;
|
|
|
|
impaledPhysicsBody.Velocity = Vector3.Zero;
|
|
|
|
impaledPhysicsBody.AngularVelocity = MathY.MoveTowards(impaledPhysicsBody.AngularVelocity, Vector3.Zero, Time.Delta * 15.0f);
|
|
|
|
impaledPhysicsBody.AngularVelocity = Vector3.Zero;
|
|
|
|
impaledPhysicsBody.Position = followToPos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//impaledPhysicsBody.Velocity = delta * 100.0f;
|
|
|
|
//impaledPhysicsBody.Position = MathY.MoveTowards(impaledPhysicsBody.Position, followToPos, Time.Delta * 1000.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float smoothRate = 0.075f;
|
|
|
|
smoothRate = 0.0001f;
|
|
|
|
|
|
|
|
float smoothRateRot = 0.075f;
|
|
|
|
//smoothRateRot = 0.0001f;
|
|
|
|
|
|
|
|
|
|
|
|
var velocity = impaledPhysicsBody.Velocity;
|
|
|
|
Vector3.SmoothDamp(impaledPhysicsBody.Position, WorldPosition, ref velocity, smoothRate, Time.Delta);
|
|
|
|
impaledPhysicsBody.Velocity = velocity;
|
|
|
|
|
|
|
|
var angularVelocity = impaledPhysicsBody.AngularVelocity;
|
|
|
|
Rotation.SmoothDamp(impaledPhysicsBody.Rotation, WorldRotation, ref angularVelocity, smoothRateRot, Time.Delta);
|
|
|
|
impaledPhysicsBody.AngularVelocity = angularVelocity;
|
|
|
|
|
|
|
|
//impaledPhysicsBody.AngularVelocity = Vector3.Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
{
|
|
|
|
if ( Network.IsOwner )
|
|
|
|
{
|
2024-10-30 13:33:29 +03:00
|
|
|
if (Input.Pressed( "Ragdoll" ))
|
2024-10-30 13:15:49 +03:00
|
|
|
{
|
2024-10-30 13:33:29 +03:00
|
|
|
Log.Info(123123);
|
|
|
|
Enabled = !Enabled;
|
2024-10-30 13:15:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnFixedUpdate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|