This commit is contained in:
Oscar 2024-10-30 01:01:41 +03:00
parent 55cf4aa1ed
commit 90084e82d5
3 changed files with 74 additions and 66 deletions

View File

@ -44,6 +44,10 @@
{
"__type": "Kal",
"__guid": "8467b849-9449-492b-b862-76c3c37aee1e",
"Body": {
"_type": "gameobject",
"go": "b99ceffc-a173-4a6e-a239-6d3c1612c09f"
},
"CamOffsetX": 200,
"CamOffsetZ": 61,
"DuckSpeed": 50,
@ -128,7 +132,6 @@
"Flags": 0,
"Name": "spine_2",
"Position": "5.610497,0.00001525879,-0.000007629395",
"Rotation": "-0.0003193617,0.001911119,-0.0103026,-0.9999417",
"Enabled": true,
"Children": [
{
@ -143,8 +146,8 @@
"__guid": "a660f880-88bb-4972-bb01-5a6a2e2d2a84",
"Flags": 0,
"Name": "head",
"Position": "4.511508,-0.0006238669,-0.0008400269",
"Rotation": "-0.000007912517,-0.0000001043081,0.01384526,-0.9998921",
"Position": "4.511506,-0.0004174262,-0.001046275",
"Rotation": "0.4999392,-0.006922714,0.01199041,-0.8659359",
"Enabled": true,
"Children": [
{

View File

@ -17,13 +17,13 @@
},
{
"__type": "Sandbox.KPTLConnect",
"__guid": "895b0f93-287e-4607-808e-6ce5bdbb5c05",
"__guid": "79db0a43-3cee-44bf-86db-fa70ca72f62c",
"PlayerPrefab": {
"_type": "gameobject",
"prefab": "prefabs/player.prefab"
},
"SpawnPoints": [],
"StartServer": true
"StartServer": false
}
]
},

View File

@ -4,39 +4,21 @@ using ShrimpleCharacterController;
public sealed class Kal : Component
{
[RequireComponent]
public ShrimpleCharacterController.ShrimpleCharacterController Controller { get; set; }
[RequireComponent]
public CitizenAnimationHelper AnimationHelper { get; set; }
[RequireComponent] public ShrimpleCharacterController.ShrimpleCharacterController Controller { get; set; }
[RequireComponent] public CitizenAnimationHelper AnimationHelper { get; set; }
public SkinnedModelRenderer Renderer { get; set; }
[Property] public GameObject Body { 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; }
[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;
[Sync] public Angles EyeAngles { get; set; }
[Sync] public bool isDucking { get; set; } = false;
[Sync] public bool isRunning { get; set; } = false;
protected override void OnStart()
{
@ -49,19 +31,17 @@ public sealed class Kal : Component
Camera.SetParent(GameObject);
var cameraComponent = Camera.Components.Create<CameraComponent>();
cameraComponent.ZFar = 32768f;
// Sandbox.Game.
}
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");
if ( Network.IsOwner )
{
var wishDirection = Input.AnalogMove.Normal * Rotation.FromYaw( EyeAngles.yaw );
isDucking = Input.Down( "Duck" );
isRunning = Input.Down( "Run" );
var wishSpeed = isDucking ? DuckSpeed :
isRunning ? RunSpeed : WalkSpeed;
@ -69,32 +49,57 @@ public sealed class Kal : Component
Controller.Move();
if (Input.Pressed("Jump") && Controller.IsOnGround)
if ( Input.Pressed( "Jump" ) && Controller.IsOnGround )
{
Controller.Punch(Vector3.Up * JumpStrength);
Controller.Punch( Vector3.Up * JumpStrength * 2f );
AnimationHelper?.TriggerJump();
}
if (!AnimationHelper.IsValid()) return;
if ( !AnimationHelper.IsValid() ) return;
}
UpdateAnimations();
}
void UpdateAnimations()
{
AnimationHelper.WithWishVelocity(Controller.WishVelocity);
AnimationHelper.WithVelocity(Controller.Velocity);
AnimationHelper.DuckLevel = isDucking ? 1f : 0f;
AnimationHelper.IsGrounded = Controller.IsOnGround;
AnimationHelper.DuckLevel = isDucking ? 1f : 0f;
}
protected override void OnUpdate()
{
base.OnUpdate();
if ( !Network.IsOwner ) return;
if ( Network.IsOwner )
{
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);
// 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;
}
RotateBody();
}
void RotateBody()
{
if(Body is null) return;
var targetAngle = new Angles(0, EyeAngles.yaw, 0).ToRotation();
float rotateDifference = Body.WorldRotation.Distance(targetAngle);
if(rotateDifference > 30f || Controller.Velocity.Length > 10f)
{
Body.WorldRotation = Rotation.Lerp(Body.WorldRotation, targetAngle, Time.Delta * 2f);
}
}
}