Add AI and Patrol components, update related resources and presenters
This commit is contained in:
@@ -11,6 +11,8 @@ namespace CryptonymThunder.Code.Presenters;
|
||||
[GlobalClass]
|
||||
public partial class CharacterBody3DPresenter : CharacterBody3D, IEntityPresenter, IPresenterComponent
|
||||
{
|
||||
[Export] private Node3D _muzzleNode;
|
||||
|
||||
private World _world;
|
||||
private VelocityComponent _velocity;
|
||||
private PositionComponent _position;
|
||||
@@ -30,7 +32,7 @@ public partial class CharacterBody3DPresenter : CharacterBody3D, IEntityPresente
|
||||
_rotation = _world.GetComponent<RotationComponent>(CoreEntity);
|
||||
_inputState = _world.GetComponent<InputStateComponent>(CoreEntity);
|
||||
_characterState = _world.GetComponent<CharacterStateComponent>(CoreEntity);
|
||||
_camera = GetNode<Camera3D>("CameraPivot/Camera3D");
|
||||
_camera = GetNodeOrNull<Camera3D>("CameraPivot/Camera3D");
|
||||
}
|
||||
|
||||
public void SyncToPresentation(float delta)
|
||||
@@ -40,8 +42,12 @@ public partial class CharacterBody3DPresenter : CharacterBody3D, IEntityPresente
|
||||
var coreRotation = _rotation.Rotation;
|
||||
Rotation = new Vector3(Rotation.X, coreRotation.Y, Rotation.Z);
|
||||
}
|
||||
|
||||
if (_velocity == null) return;
|
||||
|
||||
if (_velocity == null)
|
||||
{
|
||||
_world.Logger.Warn("No VelocityComponent found for CharacterBody3DPresenter.");
|
||||
return;
|
||||
}
|
||||
|
||||
var godotVelocity = Velocity;
|
||||
godotVelocity.X = _velocity.DesiredVelocity.X;
|
||||
@@ -57,10 +63,24 @@ public partial class CharacterBody3DPresenter : CharacterBody3D, IEntityPresente
|
||||
if (_position != null) _position.Position = GlobalPosition.ToGameCore();
|
||||
if (_velocity != null) _velocity.ActualVelocity = Velocity.ToGameCore();
|
||||
if (_characterState != null) _characterState.IsOnFloor = IsOnFloor();
|
||||
if (_inputState != null && _camera != null)
|
||||
if (_inputState != null)
|
||||
{
|
||||
_inputState.MuzzlePosition = _camera.GlobalPosition.ToGameCore();
|
||||
_inputState.MuzzleDirection = (-_camera.GlobalTransform.Basis.Z).ToGameCore();
|
||||
if (_camera != null)
|
||||
{
|
||||
_inputState.MuzzlePosition = _camera.GlobalPosition.ToGameCore();
|
||||
_inputState.MuzzleDirection = (-_camera.GlobalTransform.Basis.Z).ToGameCore();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_muzzleNode != null)
|
||||
{
|
||||
_inputState.MuzzlePosition = _muzzleNode.GlobalPosition.ToGameCore();
|
||||
}
|
||||
else
|
||||
{
|
||||
_inputState.MuzzlePosition = GlobalPosition.ToGameCore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user