Initial commit

This commit is contained in:
2023-07-09 21:04:23 -07:00
parent 970d47c2ae
commit f32534b55b
22 changed files with 409 additions and 0 deletions

12
Scripts/JRPGFollow.cs Normal file
View File

@@ -0,0 +1,12 @@
using Godot;
public partial class JRPGFollow : Node
{
[Signal]
public delegate void OnPlayerMovementEventHandler(Vector3 position);
private void OnPlayerMoveReceived(Vector3 position)
{
EmitSignal(SignalName.OnPlayerMovement, position);
}
}

51
Scripts/Player.cs Normal file
View File

@@ -0,0 +1,51 @@
using Godot;
public partial class Player : CharacterBody3D
{
[Export]
private int _speed { get; set; } = 14;
[Signal]
public delegate Vector3 MoveEventHandler();
public override void _PhysicsProcess(double delta)
{
Velocity = ProcessMovement();
MoveAndSlide();
EmitSignal(SignalName.Move, Position);
}
private Vector3 ProcessMovement()
{
var direction = Vector3.Zero;
var targetVelocity = Vector3.Zero;
if (Input.IsActionPressed("move_right"))
{
direction.X += 1.0f;
}
if (Input.IsActionPressed("move_left"))
{
direction.X -= 1.0f;
}
if (Input.IsActionPressed("move_back"))
{
direction.Z += 1.0f;
}
if (Input.IsActionPressed("move_forward"))
{
direction.Z -= 1.0f;
}
if (direction != Vector3.Zero)
{
direction = direction.Normalized();
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
}
// Ground velocity
targetVelocity.X = direction.X * _speed;
targetVelocity.Z = direction.Z * _speed;
return targetVelocity;
}
}

30
Scripts/PlayerFollow.cs Normal file
View File

@@ -0,0 +1,30 @@
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();
}
}