Raycast and collision filtering

Pretty good seeing your progress! :grinning: is in your plans creating a PR so we can get those goodies in the official repo? :thinking: :+1:

Hello,

I found an issue in official SDK : Convex hull shape isn’t processed in target C++ (Windows)…!?:upside_down_face:
deepkeras

But everything is ok for “collision filter mask”.

I created PRs :


EDIT : Merged!

3 Likes

I still don’t understand how to make raycast ignore an object, I tried setting object colliosion filter mask to certain layer and set this layer in mask in rayCast(), but still don’t work properly. Is it possible for you to update Physics_raycast example with this new feature.

Edit: nvm, I got it, the object you want ray cast to ignore set it collision mask to 2nd

1 Like

Voila, see attachment below :

colision-filter.blend (697.1 KB)

1 Like

Changing object’s collision filter mask using code during runtime using:

Scene.active.getChild("object").getTrait(RigidBody).mask = 2;

doesn’t work, any idea?

You have to update or destroy/create the nested bullet object (body).

Edit: why? This is strange operation.

First, I need to raycast to get object, than I need to raycast behind the object and get it loc, for example in my city building sim game, I need to raycast and check if ray hitted building, if it do than cast another ray to the ground and then update the building position to hit loc on plane every frame, but doing so the building is blocking the raycast from reaching the ground, so i need to above, or some other way.

Here, how it is working:


How it should be working:

(notice, cube doesn’t move unless cursor is on ground, in first gif, but cube move even when cursor is on cube in second gif)
(In second gif, cube’s collision filter mask is set to 2, this is what I hope to do with above code).
Maybe, I can just keep it the way it is.

You have to create two groups:

  • the ground in “group 1”
  • buildings in “group 2”

Accordingly, you can hit the “group 1” (ground) with the bitmask x10000.
And if you use the gravity on buildings set the mask 1 & 2 in the physic panel.

1 Like

Aight!, thanks!, got it working!

@Marc For some reason, the collision filter mask options are not showing for me in the rigid body tab? and any scene with a rigid body object throws errors? made a thread about it here with a screenshot of the error - Getting errors relating to rigid body collision masks?. Any ideas why this is happening? all the files are installed correctly, it just doesnt seem to work for me?

I figured it out. start.py was not updating in my scripts folder, had to manually copy and paste it. :slight_smile:

Now do I need to check twice for an object have both the physical collision and raycast detection?

image

I thought the “Trigger” button was to differ/toggle this :thinking:

You have to set collision filter mask even if you don’t needs raycast.

When armory engine adds an rigid body to bullet’s world, it is set group and mask.
And each frame bullet applies the rigid body’s collision mask.

I’m sorry but I’m not sure I understand.

If I keep the same setup here (only checking in collection filter), the game is working normally, only without the raycast function. Is it the expected behavior?

By default, when adding new objects, shouldn’t all raycast groups be enabled?
At first look, I don’t see a practical use of this function if before a single option toggle collision and raycast.

Wouldn’t it be better to put a button to switch whether or not the object would be detected by the raycast?

I’m going to create usecases…

2 Likes

Until…

I found two main cases to set group and masks differently:

  • raycast ( “XRAY” feature)
  • overlap triggers

bullet doc says :

Each body is part of a group. It collides with other bodies if their group matches the mask, and vise versa. The following check is performed using the group and mask of the two bodies involved. It depends on the collision filter mode.

doc from two major 3D engines (collision filtering is silghty different):

I’m familiar with these engines and now I see what you are trying to do, but by default collisions are activated for the most groups in these engines.

I was testing raycast and collision in armory 201909 and the raycast only work in ‘group 0’, despites that it’s possible to difer only collision groups.

Ray-cast work for me in all groups and masks, try updating to latest armory(2019.10)

Here I added this in CastPhysicsRayNode.hx - line 19:

override function get(from:Int):Dynamic {
...
...
if(mask==0)for(v in 0...20) mask |= (1 << v);

#if arm_physics... ...

Zero value means the same of selecting all groups, for those who have no need to filter the raycast.

edit: a better way

if(mask==0)mask=1048575;

Magic value already exists :
-1 =all groups…