Fix for barrels not exploding properly in tilemaps

This commit is contained in:
MaddoScientisto 2024-08-17 19:11:49 +02:00
commit 0eb6a9140f
5 changed files with 44 additions and 37 deletions

4
.vscode/launch.json vendored
View file

@ -13,7 +13,7 @@
"request": "launch",
"mode": "executable",
"preLaunchTask": "build",
"executable": "F:/Apps/Godot_v4.2.2-stable_mono_win64/Godot_v4.2.2-stable_mono_win64.exe",
"executable": "I:/Apps/Godot_v4.3-stable_mono_win64/Godot_v4.3-stable_mono_win64.exe",
// See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
"executableArguments": [
@ -27,7 +27,7 @@
"request": "launch",
"mode": "executable",
"preLaunchTask": "build",
"executable": "F:/Apps/Godot_v4.2.2-stable_mono_win64/Godot_v4.2.2-stable_mono_win64.exe",
"executable": "I:/Apps/Godot_v4.3-stable_mono_win64/Godot_v4.3-stable_mono_win64.exe",
// See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
"executableArguments": [

View file

@ -51,7 +51,10 @@ public partial class Barrel : Area2D, IDestructible
private void CreateParticles()
{
if (ExplosionParticles == null) {
GD.PushWarning("Object has no particles associated");
return;
}
var particle = this.CreateChild<GpuParticles2D>(ExplosionParticles);
if (particle == null) return;

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,4 @@
using Cirno.Scripts;
using Godot;
using System;
using System.Diagnostics;
@ -50,18 +51,21 @@ public partial class Enemy : Area2D
return;
}
if (IsPlayerInSight()) {
if (IsPlayerInSight())
{
// SHOOT
var bullet = BulletScene.Instantiate<Bullet>();
Owner.AddChild(bullet);
bullet.Transform = this.GlobalTransform;
bullet.Position = this.Position;
var bullet = this.CreateChild<Bullet>(BulletScene);
// var bullet = BulletScene.Instantiate<Bullet>();
// Owner.AddChild(bullet);
// bullet.Transform = this.GlobalTransform;
// bullet.Position = this.Position;
bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
}
}
private bool IsPlayerInSight() {
var spaceState = GetWorld2D().DirectSpaceState;
private bool IsPlayerInSight()
{
var spaceState = GetWorld2D().DirectSpaceState;
var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Godot.Collections.Array<Rid> { GetRid() });
var result = spaceState.IntersectRay(query);

View file

@ -8,7 +8,9 @@ public static class Tools
{
if (prefab == null) return null;
var newInstance = prefab.Instantiate<T>();
node.Owner.CallDeferred("add_child", newInstance);
node.GetParent().CallDeferred("add_child", newInstance);
// Need to use parent instead of owner because tilemap scenes have no owner
//node.Owner.CallDeferred("add_child", newInstance);
newInstance.Transform = node.GlobalTransform;
newInstance.Position = node.Position;