Is it possible to make Ray Casting avoid a spatial?

Uhh… title says it all I suppose. How could I get ray casting to avoid a certain spatial? Specifically, how could I tell a ray, or a CollisionResults instance, that a certain spatial doesn’t need to be touched.

I’m asking this because I’ve moved my shooting code to the server for Multiplayer play (the server now keeps track of it’s own game independently), so each player is attached to the server’s scene.
When a player shoots, it sends a ShootMessage containing the direction and location of the shot, and the damage of the weapon.
The server simulates the shot, and sends out HitMessages to players that were hit.

This all works fine and dandy except that since the player that’s firing is ALSO attached to the server’s scene I 100% of the time hit myself. So, would it be possible? Right now I’m thinking clone the Node, remove the player’s child, then ray test with that, but is there a faster way?

Yes and no.

You can if you know the owner of the shot and the spatial that represents the owner on the server. Just ignore this instance when parsing through the CollisionResults.

The fastest way is probably just to skip the player in the collision results.

or you can project the ray starting outside the player so that it doesn’t hit the player at all.

1 Like

Yeah, take a look at the code if BetterCharacterControl, it also just does if(objectA or objectB != myRigidBody){ … }
The content of this post is meant to be read as a straight information or question without an implicit dismissive stance or interest in having the other party feel offended unless there’s emotes that hint otherwise or there’s an increased use of exclamation marks and all-capital words.

Thanks for all the replies! I’ll hopefully be able to use this for a few more reasons.

Random side note, I’ve added sights to my game and I did a unique feature. I didn’t just make the whole FOV change on sighting so everything zooms in. I made it so the weapon’s scope, or sight, or whatever, moves up to your face, and I used Render-to-Texture to render a zoomed in version of what’s ahead into the scope or sight. It’s really cool looking, and pretty simple too. I can also use this to pass ray casts that hit this rendered screen, as well as the iron sights of a regular weapon. Thanks!

PS: What I ended up doing to rid myself of the bug with shooting iron-sights was parse through the results and only add them to the final CollisionResults instance I’d use if they met certain standards (i.e., not the player’s weapon, not the player, etc.). Hopefully that helps someone else :stuck_out_tongue:

I apologize that this is not an answer regarding your post, but I have a question. It appears that you are using ray casting for bullets in an fps game and I am doing the same thing. However, when I try to create rays for each bullet, the rays end up being created about every 30 frames or more and the rate of fire is insanely slow. I am using the same principal as the tutorial in jme3 for shooting the boxes(Tutorial 8 I think) Do you have a similar issue, if not, how did you go about making the rays?