Fps and "weapon through wall" problem

Hello everybody

Ok, as you know, i am creating a fps. I am now trying to solve some problem cient-side, and one of them is the fact that when you are too close to a wall you weapon go through it. It’s only a visual problem, as bullets are shot from the “camera” point.

I read things about it, and there is mainly 2 approach: disable the depth test and use a different viewport. The first one is not really a “fix” as it creates new problems with non-convex models.
For the second one, there is different approach.

  1. Create a new camera at a fixed position, set it to the viewport then add the weapon to the scene of this viewport. The problem with this approach is light. I GUESS this, as I didn’t test it. As the spatial is at a fixed position, the lighting will not change on it.
  2. Use the old camera with the same viewport. I prefer this one, as the weapon’s node is already attached to the client, so I don’t need to change anything. But … well, here is a picture of the result:

Imgur
I use the toonshader. The problem is : the weapon is rendered twice. I know that because the toonshader is still visible at “1” and not visible at “2”. (btw, if someone want a toon shader that only outline objects it is a way to do it  ) So, what I want to do now is to avoid the rendering of the weapon for the “normal” viewport and only render it in the “new” viewport. I tried this in the controlRender of a control attached to the weapon:

@Override
  protected void controlRender(RenderManager rm, ViewPort vp)
  {
if ( vp != theNewViewPort )
    {
      spatial.setCullHint(Spatial.CullHint.Always);
    }
    else
    {
      spatial.setCullHint(Spatial.CullHint.Never);
    }
}

However, the only result is that the weapon is always culled (for both viewport).

So, do you know a way to “skip” the rendering of a spatial for a viewport ?

Hope you have an idea.

There is a third approach I saw (i think in arma3) , if you are close to a wall, the players simply hold their weapon pointing upwards close to the body, as a normal human would do.

1 Like

yeah, and an other approach is to create a very small weapon and put it very close to the camera. But i prefer to avoid “strange” things like this.

For you solution, for example, as the game is a client-server game, i will need to detect the collision of the gun with the wall server side (as when the gun will be pointing upward, the player will find strange to be able to shoot). And the model of the weapon is not even loaded serverside (and i think it’s something good).

But thanks for the idea anyway :slight_smile:

Well think about it, this solves another problem, that you can see the world model of other players guns stucking trough doors and walls (eg counterstrike).

the model is not necessary for this, only more or less a boolean can shoot and a small raytest, based on a float defining the weapon length

I’d also do it like Arma / GTA V etc. and not let the character shoot when standing so close to a wall. Also in which situations do you actually have paper thin walls? Most of the time I guess you would have an inside and outside of the wall.

@normen said: I'd also do it like Arma / GTA V etc. and not let the character shoot when standing so close to a wall. Also in which situations do you actually have paper thin walls? Most of the time I guess you would have an inside and outside of the wall.

More often than you think, just u holding a spork in real live like a pistol would be enough to clip your houses walls if you stand close.

I’d like to second the notion that you would have your character lift or lower the gun to make it a more realistic feel. I’m going to have to implement something similar myself, but in my game, the gun will be lowered unless you are being combative.