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", "request": "launch",
"mode": "executable", "mode": "executable",
"preLaunchTask": "build", "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: // See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html // https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
"executableArguments": [ "executableArguments": [
@ -27,7 +27,7 @@
"request": "launch", "request": "launch",
"mode": "executable", "mode": "executable",
"preLaunchTask": "build", "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: // See which arguments are available here:
// https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html // https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html
"executableArguments": [ "executableArguments": [

View file

@ -51,7 +51,10 @@ public partial class Barrel : Area2D, IDestructible
private void CreateParticles() private void CreateParticles()
{ {
if (ExplosionParticles == null) {
GD.PushWarning("Object has no particles associated");
return;
}
var particle = this.CreateChild<GpuParticles2D>(ExplosionParticles); var particle = this.CreateChild<GpuParticles2D>(ExplosionParticles);
if (particle == null) return; 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 Godot;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
@ -50,18 +51,21 @@ public partial class Enemy : Area2D
return; return;
} }
if (IsPlayerInSight()) { if (IsPlayerInSight())
{
// SHOOT // SHOOT
var bullet = BulletScene.Instantiate<Bullet>(); var bullet = this.CreateChild<Bullet>(BulletScene);
Owner.AddChild(bullet); // var bullet = BulletScene.Instantiate<Bullet>();
bullet.Transform = this.GlobalTransform; // Owner.AddChild(bullet);
bullet.Position = this.Position; // bullet.Transform = this.GlobalTransform;
// bullet.Position = this.Position;
bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized()); bullet.SetDirection((_cachedPlayer.GlobalPosition - this.GlobalPosition).Normalized());
} }
} }
private bool IsPlayerInSight() { private bool IsPlayerInSight()
var spaceState = GetWorld2D().DirectSpaceState; {
var spaceState = GetWorld2D().DirectSpaceState;
var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Godot.Collections.Array<Rid> { GetRid() }); var query = PhysicsRayQueryParameters2D.Create(this.GlobalPosition, _cachedPlayer.GlobalPosition, CollisionMask, new Godot.Collections.Array<Rid> { GetRid() });
var result = spaceState.IntersectRay(query); var result = spaceState.IntersectRay(query);

View file

@ -8,7 +8,9 @@ public static class Tools
{ {
if (prefab == null) return null; if (prefab == null) return null;
var newInstance = prefab.Instantiate<T>(); 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.Transform = node.GlobalTransform;
newInstance.Position = node.Position; newInstance.Position = node.Position;