upd
This commit is contained in:
parent
55cf4aa1ed
commit
90084e82d5
@ -44,6 +44,10 @@
|
|||||||
{
|
{
|
||||||
"__type": "Kal",
|
"__type": "Kal",
|
||||||
"__guid": "8467b849-9449-492b-b862-76c3c37aee1e",
|
"__guid": "8467b849-9449-492b-b862-76c3c37aee1e",
|
||||||
|
"Body": {
|
||||||
|
"_type": "gameobject",
|
||||||
|
"go": "b99ceffc-a173-4a6e-a239-6d3c1612c09f"
|
||||||
|
},
|
||||||
"CamOffsetX": 200,
|
"CamOffsetX": 200,
|
||||||
"CamOffsetZ": 61,
|
"CamOffsetZ": 61,
|
||||||
"DuckSpeed": 50,
|
"DuckSpeed": 50,
|
||||||
@ -128,7 +132,6 @@
|
|||||||
"Flags": 0,
|
"Flags": 0,
|
||||||
"Name": "spine_2",
|
"Name": "spine_2",
|
||||||
"Position": "5.610497,0.00001525879,-0.000007629395",
|
"Position": "5.610497,0.00001525879,-0.000007629395",
|
||||||
"Rotation": "-0.0003193617,0.001911119,-0.0103026,-0.9999417",
|
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
@ -143,8 +146,8 @@
|
|||||||
"__guid": "a660f880-88bb-4972-bb01-5a6a2e2d2a84",
|
"__guid": "a660f880-88bb-4972-bb01-5a6a2e2d2a84",
|
||||||
"Flags": 0,
|
"Flags": 0,
|
||||||
"Name": "head",
|
"Name": "head",
|
||||||
"Position": "4.511508,-0.0006238669,-0.0008400269",
|
"Position": "4.511506,-0.0004174262,-0.001046275",
|
||||||
"Rotation": "-0.000007912517,-0.0000001043081,0.01384526,-0.9998921",
|
"Rotation": "0.4999392,-0.006922714,0.01199041,-0.8659359",
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"Children": [
|
"Children": [
|
||||||
{
|
{
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"__type": "Sandbox.KPTLConnect",
|
"__type": "Sandbox.KPTLConnect",
|
||||||
"__guid": "895b0f93-287e-4607-808e-6ce5bdbb5c05",
|
"__guid": "79db0a43-3cee-44bf-86db-fa70ca72f62c",
|
||||||
"PlayerPrefab": {
|
"PlayerPrefab": {
|
||||||
"_type": "gameobject",
|
"_type": "gameobject",
|
||||||
"prefab": "prefabs/player.prefab"
|
"prefab": "prefabs/player.prefab"
|
||||||
},
|
},
|
||||||
"SpawnPoints": [],
|
"SpawnPoints": [],
|
||||||
"StartServer": true
|
"StartServer": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
127
Code/Kal.cs
127
Code/Kal.cs
@ -4,41 +4,23 @@ using ShrimpleCharacterController;
|
|||||||
|
|
||||||
public sealed class Kal : Component
|
public sealed class Kal : Component
|
||||||
{
|
{
|
||||||
[RequireComponent]
|
[RequireComponent] public ShrimpleCharacterController.ShrimpleCharacterController Controller { get; set; }
|
||||||
public ShrimpleCharacterController.ShrimpleCharacterController Controller { get; set; }
|
[RequireComponent] public CitizenAnimationHelper AnimationHelper { get; set; }
|
||||||
|
|
||||||
[RequireComponent]
|
|
||||||
public CitizenAnimationHelper AnimationHelper { get; set; }
|
|
||||||
public SkinnedModelRenderer Renderer { get; set; }
|
public SkinnedModelRenderer Renderer { get; set; }
|
||||||
|
[Property] public GameObject Body { get; set; }
|
||||||
public GameObject Camera { get; set; }
|
public GameObject Camera { get; set; }
|
||||||
|
|
||||||
[Property]
|
[Property] [Range(1f, 200f, 1f)] public float CamOffsetX { get; set; }
|
||||||
[Range(1f, 200f, 1f)]
|
[Property] [Range(1f, 200f, 1f)] public float CamOffsetZ { get; set; }
|
||||||
public float CamOffsetX { 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]
|
[Property] [Range(25f, 100f, 5f)] public float DuckSpeed { get; set; } = 50f;
|
||||||
[Range(1f, 200f, 1f)]
|
[Property] [Range(200f, 500f, 20f)] public float JumpStrength { get; set; } = 350f;
|
||||||
public float CamOffsetZ { get; set; }
|
[Sync] public Angles EyeAngles { get; set; }
|
||||||
|
[Sync] public bool isDucking { get; set; } = false;
|
||||||
[Property]
|
[Sync] public bool isRunning { get; set; } = false;
|
||||||
[Range(50f, 200f, 10f)]
|
|
||||||
public float WalkSpeed { get; set; } = 100f;
|
|
||||||
|
|
||||||
[Property]
|
protected override void OnStart()
|
||||||
[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();
|
base.OnStart();
|
||||||
|
|
||||||
@ -49,52 +31,75 @@ public sealed class Kal : Component
|
|||||||
Camera.SetParent(GameObject);
|
Camera.SetParent(GameObject);
|
||||||
var cameraComponent = Camera.Components.Create<CameraComponent>();
|
var cameraComponent = Camera.Components.Create<CameraComponent>();
|
||||||
cameraComponent.ZFar = 32768f;
|
cameraComponent.ZFar = 32768f;
|
||||||
|
|
||||||
// Sandbox.Game.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFixedUpdate()
|
protected override void OnFixedUpdate()
|
||||||
{
|
{
|
||||||
base.OnFixedUpdate();
|
base.OnFixedUpdate();
|
||||||
|
|
||||||
if ( !Network.IsOwner ) return;
|
if ( Network.IsOwner )
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Controller.Punch(Vector3.Up * JumpStrength);
|
var wishDirection = Input.AnalogMove.Normal * Rotation.FromYaw( EyeAngles.yaw );
|
||||||
AnimationHelper?.TriggerJump();
|
isDucking = Input.Down( "Duck" );
|
||||||
|
isRunning = Input.Down( "Run" );
|
||||||
|
var wishSpeed = isDucking ? DuckSpeed :
|
||||||
|
isRunning ? RunSpeed : WalkSpeed;
|
||||||
|
|
||||||
|
Controller.WishVelocity = wishDirection * wishSpeed;
|
||||||
|
|
||||||
|
Controller.Move();
|
||||||
|
|
||||||
|
if ( Input.Pressed( "Jump" ) && Controller.IsOnGround )
|
||||||
|
{
|
||||||
|
Controller.Punch( Vector3.Up * JumpStrength * 2f );
|
||||||
|
AnimationHelper?.TriggerJump();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !AnimationHelper.IsValid() ) return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateAnimations();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!AnimationHelper.IsValid()) return;
|
void UpdateAnimations()
|
||||||
|
{
|
||||||
AnimationHelper.WithWishVelocity(Controller.WishVelocity);
|
AnimationHelper.WithWishVelocity(Controller.WishVelocity);
|
||||||
AnimationHelper.WithVelocity(Controller.Velocity);
|
AnimationHelper.WithVelocity(Controller.Velocity);
|
||||||
AnimationHelper.DuckLevel = isDucking ? 1f : 0f;
|
AnimationHelper.IsGrounded = Controller.IsOnGround;
|
||||||
AnimationHelper.IsGrounded = Controller.IsOnGround;
|
AnimationHelper.DuckLevel = isDucking ? 1f : 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUpdate()
|
protected override void OnUpdate()
|
||||||
{
|
{
|
||||||
base.OnUpdate();
|
base.OnUpdate();
|
||||||
|
|
||||||
|
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);
|
||||||
|
var cameraOffset = Vector3.Up * CamOffsetZ + Vector3.Backward * CamOffsetX;
|
||||||
|
|
||||||
|
Camera.WorldRotation = EyeAngles.ToRotation();
|
||||||
|
Camera.LocalPosition = cameraOffset * Camera.WorldRotation;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !Network.IsOwner ) return;
|
RotateBody();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RotateBody()
|
||||||
|
{
|
||||||
|
if(Body is null) return;
|
||||||
|
|
||||||
EyeAngles += Input.AnalogLook;
|
var targetAngle = new Angles(0, EyeAngles.yaw, 0).ToRotation();
|
||||||
EyeAngles = EyeAngles.WithPitch(MathX.Clamp(EyeAngles.pitch, -10f, 40f));
|
|
||||||
Renderer.WorldRotation = Rotation.Slerp(Renderer.WorldRotation, Rotation.FromYaw(EyeAngles.yaw), Time.Delta * 5f);
|
float rotateDifference = Body.WorldRotation.Distance(targetAngle);
|
||||||
|
|
||||||
var cameraOffset = Vector3.Up * CamOffsetZ + Vector3.Backward * CamOffsetX;
|
if(rotateDifference > 30f || Controller.Velocity.Length > 10f)
|
||||||
Camera.WorldRotation = EyeAngles.ToRotation();
|
{
|
||||||
Camera.LocalPosition = cameraOffset * Camera.WorldRotation;
|
Body.WorldRotation = Rotation.Lerp(Body.WorldRotation, targetAngle, Time.Delta * 2f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user