#Checking collider collision against another entity

1 messages · Page 1 of 1 (latest)

eager maple
#

I am trying to check if an entity is touching the collider of another entity but this code I wrote is saying the collider is touching the ground but the entity is on the air. am I doing anything obviously wrong?

[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateBefore(typeof(PhysicsSystemGroup))]
[BurstCompile]
public partial struct HitboxSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<HitboxTag>();
    }

    [BurstCompile]
    public unsafe void OnUpdate(ref SystemState state)
    {
        var physics = SystemAPI.GetSingleton<PhysicsWorldSingleton>();
        var collisionWorld = physics.CollisionWorld;

        // the docs said I need to do this
        state.CompleteDependency();

        foreach (var (collider, entity) in SystemAPI.Query<PhysicsCollider>().WithAll<HitboxTag>().WithEntityAccess())
        {
            var colliderCastInput = new ColliderCastInput
            {
                Collider = (Unity.Physics.Collider*)collider.Value.GetUnsafePtr(),
                Orientation = quaternion.identity,
            };

            if (collisionWorld.CastCollider(colliderCastInput, out var hit))
            {
                Debug.Log($"hit: {hit.Entity}");
            }
        }
    }
}
#

it looks like ColliderCastInput has a Start and End values but I am not sure how I should use them, all I want to do is to check if a collider is intersecting another

deft pine
#

so start and end are very nearby values

eager maple
#

oh I just added both start and end values to be the same as the LocalTransform of the entity and it seems to have worked, thanks for the hint

#

btw is this code "correct" for what I am trying to do? I am reading about this physics stuff for more than 2 hours and everything looks so complex that I have no idea what I am doing atwhatcost so many different ways to do stuff

deft pine
#

I think you can just pass blob asset reference

#

no need for ptr

eager maple
#

to add a bit of context, this is for the skill hitboxes so I am basically trying to check if the colliders in the Hitbox layer are colliding with the colliders in the Hurtbox layer. if so I add some components in the hit.Entity entity. I read about StatefulCollisionEvents but I am not sure I really need that

deft pine
#

collision events only happen when physics body collide via physics world loop

#

if you move them via LocalTransform

#

you won't get them

eager maple
#

uh this sounds like a problem. do you mean if I have a hurtbox in a moving enemy (e.g., using a CharacterController) and it enters the hitbox range, then the event won't trigger?

eager maple
deft pine
#

collider.Value I think

#

in constructor

#

not in field

eager maple