Jump to content

Custom Physics Collision groups?


Recommended Posts

I've been trying to clean up my hitbox system recently, since there are a number of different types of hurtboxes that are constantly running onCollisionCallbacks because they all need to be layered over the character at once, despite having nothing to do with each other. 

I've been using SetCollisionGroup(COLLISION.SANITY)  Because all these collisions interact with each other without touching the player, but I've also been trying to find some custom numbers in place of these presets. After all, collision.sanity is just 4096 (all the collision numbers are spaced weirdly far apart from each other. anyone know why?)

Are all of the collision groups locked behind the scenes of the game's code? I'd love to be able to set my own custom collision groups, so that ledge-detection hitboxes collide with ledge-grabbable boxes, but not with each other. or at least have a better understanding of how to tell what collides with what, because it's been a little foggy for me given nothing but a number. 

I'm not sure if anyone has ever played around with this in the past, or has any interest in it.

Link to comment
Share on other sites

6 hours ago, pickleplayer said:

collision.sanity is just 4096 (all the collision numbers are spaced weirdly far apart from each other. anyone know why?)

Klei are probably using bits to represent collision layer masks for cheap collision checks. 4096 is the 16th bit 0001000000000000.

Edited by Ultroman
Link to comment
Share on other sites

2 hours ago, Ultroman said:

Klei are probably using bits to represent collision layer masks for cheap collision checks. 4096 is the 16th bit 0001000000000000.

Yes, this is correct.

 

From constants.lua:

COLLISION =
{

    GROUND = 64, -- See BpWorld.cpp (ocean walls)
    LIMITS = 128,
    WORLD = 192, --limits and ground
    ITEMS = 256,
    OBSTACLES = 512,
    CHARACTERS = 1024,
    FLYERS = 2048,
    SANITY = 4096,
    SMALLOBSTACLES = 8192,	-- collide with characters but not giants
    GIANTS = 16384,	-- collide with obstacles but not small obstacles
}

64 + 128 = 192, as noted by the comments 'world' is the combination of 'ground' and 'limits'.

Every number here should be represented by 2^x by itself to denote its own collision mask.

 

From my testings it would seem to imply that the engine is a full 32 bit for this mask, but you're limited.

There are two constants on the C-side that force a min/max on this bitmask.

Assert failure 'group >= COLLISION_GROUP_MIN && group <= COLLISION_GROUP_MAX' at ..\source\game\components\PhysicsComponent.cpp(537): Trace follows...

 

COLLISION_GROUP_MIN = 0 and COLLISION_GROUP_MAX = 16384

Any integer value touching and in between these two are valid to the engine at this time.

What masks 1, 2, 4, 8, 16, and 32 represent are unknown to me.  You might be able to get more data by asking one of the Klei devs on it.

Link to comment
Share on other sites

13 hours ago, CarlZalph said:

What masks 1, 2, 4, 8, 16, and 32 represent are unknown to me.  You might be able to get more data by asking one of the Klei devs on it.

 

Ooooh that's Interesting! 8 and 32 are both values that don't seem to collide with anything that I can see in my world. My tiny, barren world with player character collision turned off.. so I could just be missing it.

But that's an additional 2 sets of hitbox types that I can use to interact with each other without triggering the collision on all the other types, so that's perfect!

Seems all the other custom number types simply collide with everything. So even though I can't create my own, I've got a number of pre-set values to use

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...