Fix really really really annoying issue with enemy spawns
Godot refuses to set CharacterBody3D positions correctly unless you call ResetPhysicsInterpolation immediately after
This commit is contained in:
@@ -21,11 +21,13 @@ public abstract partial class Enemy2D : Enemy
|
||||
public void OnEnterTree()
|
||||
{
|
||||
LineOfSight.BodyEntered += LineOfSight_BodyEntered;
|
||||
_previousPosition = GlobalPosition;
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_enemyModelView.SetCurrentDirection(GlobalBasis, -_player.GlobalBasis.Z);
|
||||
_previousPosition = GlobalPosition;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
@@ -37,7 +39,6 @@ public abstract partial class Enemy2D : Enemy
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Idle());
|
||||
else
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Move());
|
||||
_previousPosition = GlobalPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ public abstract partial class Enemy2D : Enemy
|
||||
|
||||
protected void OnVelocityComputed(Vector3 safeVelocity)
|
||||
{
|
||||
Velocity = safeVelocity;
|
||||
Velocity = new Vector3(safeVelocity.X, 0, safeVelocity.Z);
|
||||
LookAtTarget(safeVelocity);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ public partial class PatrolBehavior : Node3D, IBehavior
|
||||
private Timer _patrolTimer { get; set; } = default!;
|
||||
private NavigationAgent3D _navigationAgent;
|
||||
|
||||
private int _recursiveCounter = 0;
|
||||
private Vector3 _homePosition;
|
||||
|
||||
public Vector3 HomePosition
|
||||
|
||||
@@ -412,8 +412,16 @@ public partial class Game : Node3D, IGame
|
||||
{
|
||||
var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn");
|
||||
var restorative = restorativeScene.Instantiate<Restorative>();
|
||||
AddChild(restorative);
|
||||
restorative.GlobalPosition = new Vector3(vector.X, 2f, vector.Z) + (-_player.GetGlobalBasis().Z);
|
||||
AddChild(restorative);
|
||||
}
|
||||
|
||||
private void DropItem(Vector3 vector)
|
||||
{
|
||||
var randomItem = ItemDatabase.Instance.PickItem<IBaseInventoryItem>() as Node3D;
|
||||
var duplicated = randomItem.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D;
|
||||
duplicated.GlobalPosition = new Vector3(vector.X, 2f, vector.Z) + (-_player.GetGlobalBasis().Z);
|
||||
AddChild(duplicated);
|
||||
}
|
||||
|
||||
private void UseTeleportPrompt_CloseTeleportPrompt()
|
||||
@@ -691,6 +699,11 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
private void GameRepo_EnemyDied(IEnemy obj)
|
||||
{
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
if (rng.Randf() < 0.15f)
|
||||
DropItem(obj.GlobalPosition);
|
||||
else
|
||||
DropRestorative(obj.GlobalPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ public class EffectService
|
||||
var enemyPosition = new Vector3(enemy.GlobalPosition.X, 0f, enemy.GlobalPosition.Z);
|
||||
var enemyType = EnemyTypeToEnemyConverter.Convert(enemy);
|
||||
var duplicatedEnemy = EnemyTypeToEnemyConverter.Convert(enemyType);
|
||||
duplicatedEnemy.Position = enemy.GlobalPosition + enemy.GlobalBasis.X;
|
||||
duplicatedEnemy.GlobalPosition = enemy.GlobalPosition + enemy.GlobalBasis.X;
|
||||
_map.AddChild(duplicatedEnemy);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,5 +33,6 @@ shape = SubResource("BoxShape3D_03cqg")
|
||||
unique_name_in_owner = true
|
||||
pixel_size = 0.005
|
||||
billboard = 2
|
||||
alpha_cut = 1
|
||||
texture_filter = 0
|
||||
render_priority = 100
|
||||
|
||||
@@ -2,7 +2,6 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -41,8 +40,9 @@ public partial class MonsterRoom : DungeonRoom
|
||||
var index = rng.RandWeighted([.. enemyInfo.Values]);
|
||||
var selectedEnemy = enemyInfo.ElementAt((int)index);
|
||||
var instantiatedEnemy = EnemyTypeToEnemyConverter.Convert(selectedEnemy.Key);
|
||||
instantiatedEnemy.Position = new Vector3(spawnPoint.Position.X, 0f, spawnPoint.Position.Z);
|
||||
AddChild(instantiatedEnemy);
|
||||
instantiatedEnemy.GlobalPosition = new Vector3(spawnPoint.GlobalPosition.X, 0f, spawnPoint.GlobalPosition.Z);
|
||||
ResetPhysicsInterpolation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public partial class MonsterRoom : DungeonRoom
|
||||
|
||||
var selectedItem = database.PickItem<IBaseInventoryItem>() as Node3D;
|
||||
var duplicated = selectedItem.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D;
|
||||
duplicated.Position = new Vector3(spawnPoint.Position.X, 0, spawnPoint.Position.Z);
|
||||
duplicated.GlobalPosition = new Vector3(spawnPoint.GlobalPosition.X, 0, spawnPoint.GlobalPosition.Z);
|
||||
AddChild(duplicated);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user