-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#16 Udemy 2.5D RPG Enemies patrolling
- Loading branch information
John Ludlow
committed
Sep 6, 2024
1 parent
3b2a2be
commit 6c26b21
Showing
7 changed files
with
234 additions
and
32 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Udemy25dRpg.Scenes.Characters.Enemy; | ||
|
||
public partial class EnemyPatrolState : StateMachineStateBase | ||
{ | ||
private int _pathNodeIndex = 0; | ||
|
||
protected override void EnterState() | ||
{ | ||
_characterNode.AnimatedSprite3DNode.Play(nameof(Enemy.EnemyAnimations.Move)); | ||
} | ||
|
||
public override void _PhysicsProcess(double delta) | ||
{ | ||
base._PhysicsProcess(delta); | ||
|
||
if (_characterNode.NavigationAgentNode.IsNodeReady() && _characterNode.NavigationAgentNode.IsNavigationFinished()) | ||
{ | ||
if (_pathNodeIndex >= _characterNode.PathNode.Curve.PointCount) | ||
{ | ||
_pathNodeIndex = 0; | ||
} | ||
|
||
_characterNode.NavigationAgentNode.TargetPosition = | ||
_characterNode.PathNode.Curve.GetPointPosition(_pathNodeIndex++) + | ||
_characterNode.PathNode.GlobalPosition; | ||
} | ||
|
||
_characterNode.Velocity = _characterNode.GlobalPosition.DirectionTo(_characterNode.NavigationAgentNode.TargetPosition); | ||
_characterNode.MoveAndSlide(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Godot; | ||
|
||
namespace Udemy25dRpg.Scenes.Characters.Enemy; | ||
|
||
public partial class EnemyReturnState : StateMachineStateBase | ||
{ | ||
private Vector3 _destination; | ||
|
||
public override void _Ready() | ||
{ | ||
base._Ready(); | ||
|
||
_destination = | ||
_characterNode.PathNode.Curve.GetPointPosition(0) + | ||
_characterNode.PathNode.GlobalPosition; | ||
} | ||
|
||
protected override void EnterState() | ||
{ | ||
_characterNode.AnimatedSprite3DNode.Play(nameof(Enemy.EnemyAnimations.Move)); | ||
_characterNode.NavigationAgentNode.TargetPosition = _destination; | ||
} | ||
|
||
public override void _PhysicsProcess(double delta) | ||
{ | ||
if (_characterNode.NavigationAgentNode.IsNavigationFinished()) | ||
{ | ||
_characterNode.StateMachineNode.SwitchState<EnemyPatrolState>(); | ||
return; | ||
} | ||
|
||
_characterNode.Velocity = _characterNode.GlobalPosition.DirectionTo(_destination); | ||
_characterNode.MoveAndSlide(); | ||
} | ||
} |
Oops, something went wrong.