I have multiple spaceships (SHIP_CB
CbType), that can all shoot missiles (BULLET_CB
CbType). How do I set up there sensorGroup
, sensorMask
and InteractionListeners
so I get the following behaviour:
Is it even possible to get all these behaviours just by setting the correct sensorGroup and sensorMask on each object?
Assuming bullets are only ever going to sense, and so should not interact in any way with the ship that shot them, one way would be:
Starting with everything defaulted,
for each ship
ship.group = new InteractionGroup(true);
for each bullet created for a given ship 'ship'
Set bullet to have the same interaction group as the ship who shot it. that way, since ignore=true on group, any bullet fired from a given ship will be excluded from interacting with that ship.
bullet.group = ship.group;
for each shape of the bullet, probably only 1. make bullet shape sensor
bulletShape.sensorEnabled = true;
make bullet shapes sense with everything except for themselves.
bulletShape.sensorGroup = 2; bulletShape.sensorMask = ~2;
ref: Nape Manual: InteractionGroups
You 'could' do this purely with sensorGroup/sensorMask. but you'd be restricted to 31 different ships and the logic would be a bit more complex.
You 'could' also use callback system to ignore interactins between a ship and the bullets it fires with some extra logic in the callback, but it'd be a lot heavier than using the InteractionGroup stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With