Collision Mask Identifiers / Multiple Collision Masks #7160
AnseloOriginal
started this conversation in
Good First Contribution
Replies: 1 comment
-
see if this works: // MultipleCollisionMasks.js
// Extension for GDevelop to support collision checks with specific mask IDs
const extension = new gdjs.Extension();
// Metadata
extension.setExtensionInformation(
"MultipleCollisionMasks",
"Multiple Collision Masks",
"Allows checking collisions for specific collision masks of a sprite object using mask IDs.",
"Your Name",
"MIT"
);
// Condition: Check collision with a specific mask
extension
.addCondition(
"CheckCollisionWithMask",
"Check collision with specific mask",
"Checks if a specific collision mask of an object collides with another object.",
"Mask _PARAM2_ of _PARAM0_ collides with _PARAM1_",
"Collisions",
"res/conditions/collision24.png"
)
.addParameter("object", "Object with multiple collision masks", "", false)
.addParameter("object", "Object to check collision against", "", false)
.addParameter("number", "Mask identifier (e.g., 0, 1, 2)", "", false)
.setFunctionName("gdjs.evtTools.collision.checkCollisionWithMask");
// Runtime function to handle the collision check
gdjs.evtTools.collision = gdjs.evtTools.collision || {};
gdjs.evtTools.collision.checkCollisionWithMask = function(obj1, obj2, maskId) {
if (!obj1 || !obj2) return false;
// Assume obj1 is a SpriteRuntimeObject with _collisionMasks array
const sprite1 = obj1;
const mask = sprite1._collisionMasks ? sprite1._collisionMasks.find(m => m.id === maskId) : null;
if (!mask) return false;
// Perform collision check using the specific mask's shape
// This assumes the runtime has been modified to support mask.shape
return gdjs.RuntimeObject.collisionTest(obj1, obj2, mask.shape);
};
// Register the extension
gdjs.registerExtension(extension); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a feature that allows the creation of multiple collision masks. The masks are automatically numbered, with the first one created by the system during sprite creation being numbered #0.
Features:
Multiple Collision Masks: This is useful for testing different collisions on different parts of an object, such as a human sprite, rather than creating multiple sprites.
Automatic Numbering by the Engine: The system automatically numbers the collision masks.
I think this is feasible because, although you can already create more than one collision mask, you currently can’t use them separately.
Beta Was this translation helpful? Give feedback.
All reactions