[SOLVED] How to shoot a projectile from within character and skip the very char and hit everything else?

I thought on collision groups, EDIT: but cant find a way to make it work.

What I have been doing it spawn the projectile a bit in-front of the character and throw it, but then, if I am touching on a wall, the projectile will spawn inside of it…

Also if I set the collision group to something else than default, and later set it back to the default, the problem is how later I would have to do that, and til then the projectile may already have gone beyond the wall…

Should I cast ray or something to determine the initial spawn position?

EDIT: also, I thought, if we could control the collision itself, so I could check what collided and skip the collision event preventing all applied impulses and forces that way too, like being a ghost.

I am thinking on using PhysicsTickListener, and at prePhysicsTick() backup the projectile and character forces and velocities;

then, if they collide, at physicsTick() i restore the backups to both projectile and character, someone think it may work? or I may just create another problem by restoring the physics in this so simple way?

Collision groups work different than you probably think, read the javadoc. Theres collision groups and collideWith groups.

so, if I put:

  • the terrain and walls at collisionGroup 1, and to collide with nothing

  • all chars at collisionGroup 2, and to collide with 1, 2 and 3
    so they collide with walls and terrain,
    with other chars, and
    with projectiles (but then the char will collide with his own projectile too)

  • the projectile at collisionGroup 3, and to collide with 1, 2 and 3
    so it can hit chars (even the one that fired it :frowning: )
    terrain, walls and other projectiles (thrown debris, etc)

It doesnt seem this problem should use the collision groups to be solved, or am I missing something in the logic?

My goal also is to the projectile initially ignore who fired it, but if it fall on his head (if thrown upwards) or ricochets on a wall, I still want it to hit the char who fired it.

btw, I found this question too, that ppl didnt report if they succeed

Ah, well you might get somewhere with collision group listeners then, with these you can drop collisions before they happen based on custom checks (e.g. if your character just fired the bullet).

1 Like

may be:

Having the projectile at group 3, and do not still set it collide with group 2 (chars).
It would still hit walls, but not chars yet.
When it moves away from who fired it radius; I set it to collide with group 2; so other chars, ricochets and fall over head, would start working.

The only problem I see now is in case two chars are too close, and the projectile could be thrown so fast that it pass over the other char, but I think that may be worked later…

I will try it and see if it works.

PhysicsCollisionGroupListener works really great!
I still had to stop ignoring collision just after if moves enough away from, who thrown it, radius (so it can fall and hit him back)

Would it not be better to have a node hanging off the character or it’s weapon which could act as a projectile spawn point and spawn it outside the character collision box?

the problem with that is that if you are touching a thin wall (or even a normal wall), the projectile may spawn behind it (or inside of it),
may be a ray could be cast before spawning the the projectile but still what would I do? if I want it to ricochet, I am forced to spawn it anyway

also, the char radius check is not a good approach, better is check if projectile is still inside of char spatial or char gun, and when it leave that area, set to to allow colliding again with char/gun