2024-10-29 18:52:47 +03:00
|
|
|
using Sandbox.Citizen;
|
|
|
|
using ShrimpleCharacterController;
|
|
|
|
|
|
|
|
public sealed class Kal : Component
|
|
|
|
{
|
|
|
|
[RequireComponent]
|
|
|
|
public ShrimpleCharacterController.ShrimpleCharacterController Controller { get; set; }
|
|
|
|
|
|
|
|
[RequireComponent]
|
|
|
|
public CitizenAnimationHelper AnimationHelper { get; set; }
|
|
|
|
public SkinnedModelRenderer Renderer { get; set; }
|
|
|
|
public GameObject Camera { get; set; }
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(1f, 200f, 1f)]
|
|
|
|
public float CamOffsetX { get; set; }
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(1f, 200f, 1f)]
|
|
|
|
public float CamOffsetZ { get; set; }
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(50f, 200f, 10f)]
|
|
|
|
public float WalkSpeed { get; set; } = 100f;
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(100f, 500f, 20f)]
|
|
|
|
public float RunSpeed { get; set; } = 300f;
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(25f, 100f, 5f)]
|
|
|
|
public float DuckSpeed { get; set; } = 50f;
|
|
|
|
|
|
|
|
[Property]
|
|
|
|
[Range(200f, 500f, 20f)]
|
|
|
|
public float JumpStrength { get; set; } = 350f;
|
|
|
|
|
|
|
|
public Angles EyeAngles { get; set; }
|
|
|
|
|
|
|
|
protected override void OnStart()
|
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
|
|
|
|
if ( !Network.IsOwner ) return;
|
|
|
|
|
|
|
|
Renderer = Components.Get<SkinnedModelRenderer>(FindMode.EverythingInSelfAndDescendants);
|
|
|
|
Camera = new GameObject(true, "Camera");
|
|
|
|
Camera.SetParent(GameObject);
|
|
|
|
var cameraComponent = Camera.Components.Create<CameraComponent>();
|
|
|
|
cameraComponent.ZFar = 32768f;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnFixedUpdate()
|
|
|
|
{
|
|
|
|
base.OnFixedUpdate();
|
|
|
|
|
|
|
|
if ( !Network.IsOwner ) return;
|
|
|
|
|
|
|
|
var wishDirection = Input.AnalogMove.Normal * Rotation.FromYaw(EyeAngles.yaw);
|
|
|
|
var isDucking = Input.Down("Duck");
|
|
|
|
var isRunning = Input.Down("Run");
|
|
|
|
var wishSpeed = isDucking ? DuckSpeed :
|
|
|
|
isRunning ? RunSpeed : WalkSpeed;
|
|
|
|
|
|
|
|
Controller.WishVelocity = wishDirection * wishSpeed;
|
|
|
|
|
|
|
|
Controller.Move();
|
|
|
|
|
|
|
|
if (Input.Pressed("Jump") && Controller.IsOnGround)
|
|
|
|
{
|
2024-10-29 18:55:34 +03:00
|
|
|
Controller.Punch(Vector3.Up * JumpStrength);
|
2024-10-29 18:52:47 +03:00
|
|
|
AnimationHelper?.TriggerJump();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AnimationHelper.IsValid()) return;
|
|
|
|
|
|
|
|
AnimationHelper.WithWishVelocity(Controller.WishVelocity);
|
|
|
|
AnimationHelper.WithVelocity(Controller.Velocity);
|
|
|
|
AnimationHelper.DuckLevel = isDucking ? 1f : 0f;
|
|
|
|
AnimationHelper.IsGrounded = Controller.IsOnGround;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
{
|
|
|
|
base.OnUpdate();
|
|
|
|
|
|
|
|
if ( !Network.IsOwner ) return;
|
|
|
|
|
|
|
|
Log.Info(Controller.WishVelocity);
|
|
|
|
|
|
|
|
EyeAngles += Input.AnalogLook;
|
|
|
|
EyeAngles = EyeAngles.WithPitch(MathX.Clamp(EyeAngles.pitch, -10f, 40f));
|
|
|
|
Renderer.WorldRotation = Rotation.Slerp(Renderer.WorldRotation, Rotation.FromYaw(EyeAngles.yaw), Time.Delta * 5f);
|
|
|
|
|
|
|
|
var cameraOffset = Vector3.Up * CamOffsetZ + Vector3.Backward * CamOffsetX;
|
|
|
|
Camera.WorldRotation = EyeAngles.ToRotation();
|
|
|
|
Camera.LocalPosition = cameraOffset * Camera.WorldRotation;
|
|
|
|
}
|
|
|
|
}
|