Question
I’m making hitbox collisions for my fighting game and I’m trying to use Aabb but the results don’t make any sense. The hitboxes ColliisonCheck function is running in a hitbox manager class and it I have confermed it is running that function for every hit box in the manager class but it just doesn’t work as intended. This is how it functions.
Blue are hurt boxes. Red are hit boxes.
whenever a hitbox collides it prints the hurtbox’s position and scale
this is the code
using System.Collections.Generic;
using Godot;
namespace ProjectKazen.Framework.FGAnimation;
[GlobalClass]
[Tool]
public partial class FightBox : Node3D
{
public class Debug : Framework.Debug.Base
{
public CsgBox3D Visual = new(){};
}
public void Destroy()
{
GetParent().RemoveChild(this);
Manager?.Remove(this);
QueueFree();
}
protected Debug DebugDisplay = new(){IsActive = true};
[Export]
bool DummyBox;
public virtual FightBoxInfo BasicInfo => new();
Aabb CollisionData => new(GlobalPosition + (BasicInfo.Position * GlobalBasis.GetRotationQuaternion()),BasicInfo.Size);
public bool Active;
protected delegate void CollisionEventHandeler(GodotObject With);
public BasePlayer Player {get;private set;}
protected FGAnimationPlayer AnimationPlayer;
FightBoxManager Manager;
public List<GodotObject> CollidingObjects = new();
public bool IsColliding => CollidingObjects.Count > 0;
public void CollisionCheck(FightBox Other)
{
bool HasOtherInCollisionList = false;
bool IsExcluded = false;
foreach(FightBox Box in CollidingObjects)
{
if (Box.Equals(Other))
{
HasOtherInCollisionList = true;
}
}
foreach(GodotObject Box in Excluded)
{
if (Box.Equals(Other))
{
IsExcluded = true;
}
}
if (CollisionData.Intersects(Other.CollisionData))
{
if (!HasOtherInCollisionList && !IsExcluded)
{
GD.Print(Other.CollisionData.Size);
GD.Print(Other.CollisionData.Position);
CollidingObjects.Add(Other);
}
}
else
{
if(HasOtherInCollisionList)
CollidingObjects.Remove(Other);
}
//GD.Print(CollidingObjects.Count);
}
public int Number;
public T HasCollObject<T>() where T : GodotObject
{
GodotObject OBJReturn = null;
foreach(GodotObject OBJ in CollidingObjects)
{
if (OBJ.GetType().Equals(typeof(T)))
{
OBJReturn = OBJ;
}
}
return (T)OBJReturn;
}
public List<GodotObject> Excluded = [];
public static void ResetCopyTrans(Node Parent)
{
foreach (Node Child in Parent.GetChildren())
{
if(Child is RemoteTransform3D Trans)
{
Parent.RemoveChild(Trans);
}
}
}
public override void _Ready()
{
if (!DummyBox && !Engine.IsEditorHint())
{
AnimationPlayer = (FGAnimationPlayer)GetParent().GetParent();
Player = AnimationPlayer.GetParent<BasePlayer>();
Player.Time = 1;
}
if (DebugDisplay.IsActive && BasicInfo is not null)
{
DebugDisplay.Visual.Size = BasicInfo.Size;
DebugDisplay.Visual.Position = BasicInfo.Position;
AddChild(DebugDisplay.Visual);
DebugDisplay.Visual.Owner = Engine.IsEditorHint() ? GetTree().EditedSceneRoot: GetTree().Root;
}
}
public override void _Process(double delta)
{
base._Process(delta);
if(DebugDisplay.IsActive && BasicInfo is not null)
{
DebugDisplay.Visual.Size = BasicInfo.Size;
DebugDisplay.Visual.Position = BasicInfo.Position;
}
}
public void Init(FightBoxManager Manager)
{
this.Manager = Manager;
this.Manager.Add(this);
}
public FightBox()
{
Excluded.Add(this);
/*
Entered += Enter;
Exited += (Body) =>
{
Collisions.Remove(Body);
};*/
}
}