31 lines
1010 B
C#
31 lines
1010 B
C#
using Godot;
|
|
|
|
public partial class PlayerFollow : CharacterBody3D
|
|
{
|
|
[Export]
|
|
private double _timeToWait { get; set; } = 0.1;
|
|
[Export]
|
|
private Vector3 _followDistance { get; set; } = new Vector3(0, 0, -2);
|
|
|
|
private async void OnMainOnPlayerMovement(Vector3 position)
|
|
{
|
|
// await ToSignal(GetTree().CreateTimer(_timeToWait), "timeout");
|
|
// Position = Position.Lerp(position, 1);
|
|
// MoveAndSlide();
|
|
// if (position != Vector3.Zero)
|
|
// GetNode<Node3D>("Pivot").LookAt(position, Vector3.Up);
|
|
}
|
|
|
|
public override async void _PhysicsProcess(double delta)
|
|
{
|
|
await ToSignal(GetTree().CreateTimer(_timeToWait), "timeout");
|
|
var player = GetNode<CharacterBody3D>("../Player");
|
|
if (Position.DistanceTo(player.Position) > 2.0f)
|
|
Position = Position.Lerp(player.Position + _followDistance * (Position - player.Position), (float)delta * 4.0f);
|
|
|
|
if (Velocity != Vector3.Zero)
|
|
GetNode<Node3D>("Pivot").LookAt(Velocity, Vector3.Up);
|
|
MoveAndSlide();
|
|
}
|
|
}
|