Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] 2D Collision Filtering Question

Author
Message
Wizzkid
AGK Tool Maker
17
Years of Service
User Offline
Joined: 14th Aug 2006
Location: Northern Ireland
Posted: 31st Dec 2019 15:28
I have two types of sprites in my level, blocks and balls. I would like balls to collide with blocks, but not with other balls. Anyone know of a way to achieve this?

Thanks!

The author of this post has marked a post as an answer.

Go to answer

smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 31st Dec 2019 16:18 Edited at: 31st Dec 2019 16:20
This post has been marked by the post author as the answer.
use SetSpriteCategoryBit and SetSpriteCollideBit
Quote: "Sets or removes a category that this sprite can collide with. Sprites are assigned categories using SetSpriteCategoryBit. There are 16 categories, a value of 1 for that category represents that this sprite will collide with sprites from that category and 0 that it will not collide with that category, regardless of which category this sprite itself belongs to. By default all sprites belong to category 1 and collide with all categories. This command is similar to SetSpriteCategoryBits except this command sets one category at a time whilst that command sets them all at once using a bit mask.

By default this sets all shapes to the same value, you can set this value on a per shape basis by specifying a shapeID value greater than 0. Shape IDs start at 1 for the first shape, with shapeID 0 meaning apply it to all shapes.

Definition
SetSpriteCollideBit( iSpriteIndex, category, flag, shapeID )

SetSpriteCollideBit( iSpriteIndex, category, flag )

Parameters
iSpriteIndex - The ID of the sprite to modify.
category - The category to set collision on or off for this sprite, must be between 1 and 16 inclusive.
flag - 1 to set collision on, 0 to turn it off for this sprite.
shapeID - the ID of the shape to change, 0 to set all the sprite's shapes to this value"
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
Wizzkid
AGK Tool Maker
17
Years of Service
User Offline
Joined: 14th Aug 2006
Location: Northern Ireland
Posted: 31st Dec 2019 17:39
Thanks! That's exactly what I was after

Login to post a reply

Server time is: 2024-03-29 08:15:42
Your offset time is: 2024-03-29 08:15:42