Buddy system
This commit is contained in:
@@ -14,8 +14,8 @@ public partial class CameraSystem : SpringArm3D
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_pivot = GetNode<Node3D>("/root/Main/CharacterBody3D/Pivot");
|
||||
_characterBody = GetNode<CharacterBody3D>("/root/Main/CharacterBody3D");
|
||||
_pivot = GetNode<Node3D>("/root/Main/Player/Pivot");
|
||||
_characterBody = GetNode<CharacterBody3D>("/root/Main/Player");
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
||||
32
Scripts/NPCFollow.cs
Normal file
32
Scripts/NPCFollow.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Godot;
|
||||
|
||||
public partial class NPCFollow : CharacterBody3D
|
||||
{
|
||||
[Export]
|
||||
private float _speed = 5f;
|
||||
[Export]
|
||||
private double _followDistance = 2;
|
||||
|
||||
private Node3D _player;
|
||||
public const float JumpVelocity = 4.5f;
|
||||
|
||||
public float _gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_player = GetNode<Node3D>("/root/Main/Player");
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var playerPosition = _player.Position;
|
||||
var targetPosition = (playerPosition - Position).Normalized();
|
||||
|
||||
if (Position.DistanceTo(playerPosition) >= _followDistance)
|
||||
{
|
||||
LookAt(playerPosition - Velocity, Vector3.Up);
|
||||
Velocity = Velocity.Slerp(targetPosition * _speed, 0.5f);
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Godot;
|
||||
|
||||
public partial class CharacterBody3D : Godot.CharacterBody3D
|
||||
public partial class Player : CharacterBody3D
|
||||
{
|
||||
public const float Speed = 5.0f;
|
||||
public const float JumpVelocity = 4.5f;
|
||||
@@ -15,14 +15,14 @@ public partial class CharacterBody3D : Godot.CharacterBody3D
|
||||
private Node3D _cameraMount;
|
||||
private Node3D _pivot;
|
||||
|
||||
// Get the gravity from the project settings to be synced with RigidBody nodes.
|
||||
public float gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
|
||||
// Get the _gravity from the project settings to be synced with RigidBody nodes.
|
||||
public float _gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Input.MouseMode = Input.MouseModeEnum.Captured;
|
||||
_cameraMount = GetNode<Node3D>("/root/Main/CharacterBody3D/CameraMount");
|
||||
_pivot = GetNode<Node3D>("/root/Main/CharacterBody3D/Pivot");
|
||||
_cameraMount = GetNode<Node3D>("/root/Main/Player/CameraMount");
|
||||
_pivot = GetNode<Node3D>("/root/Main/Player/Pivot");
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
@@ -35,16 +35,12 @@ public partial class CharacterBody3D : Godot.CharacterBody3D
|
||||
{
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
// Add the gravity.
|
||||
if (!IsOnFloor())
|
||||
velocity.Y -= gravity * (float)delta;
|
||||
velocity.Y -= _gravity * (float)delta;
|
||||
|
||||
// Handle Jump.
|
||||
if (Input.IsActionJustPressed("jump") && IsOnFloor())
|
||||
velocity.Y = JumpVelocity;
|
||||
|
||||
// Get the input direction and handle the movement/deceleration.
|
||||
// As good practice, you should replace UI actions with custom gameplay actions.
|
||||
Vector2 inputDir = Input.GetVector("right", "left", "back", "forward");
|
||||
Vector3 direction = (Transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized();
|
||||
if (direction != Vector3.Zero)
|
||||
Reference in New Issue
Block a user