[SOLVED] Raycast does not detect the collision when shooting from top to bottom

I have a problem with raycast when shooting. When a player is standing on the ground and shooting, the raycast works correctly. But when I shoot from top to bottom, for example in a jump, the raycast often does not work. Tell me, please, how can I solve the problem?

I attach 2 gif, which shows shooting on the ground and in a jump, as well as a link to the project: https://playcanvas.com/editor/scene/694807

It works correctly: http://g.recordit.co/9MmYSi2Adp.gif

It works incorrectly: http://g.recordit.co/GpINPfwkUb.gif

1 Like

I’ve had a look at it and reduced the issue somewhat by swapping the values of ray from and to (still you don’t fire a ray from inside the box).

However, the issue is still happening and I can’t work out why. I’ve slowed down the bullet and created a ‘ray’ so I can see the travel path of the bullet and it looks like it just goes through the box.

Progress so far: https://playcanvas.com/editor/scene/695940

1 Like

This caught my attention because of the raycast issue I had with the camera having been scaled. This camera is not scaled though. But it is parented to a player object that is scaled on all three axes to 0.5, 0.5, 0.5. Is it possible that scaling the camera to 2, 2, 2 would compensate and fix? Just a thought. Probably not right, but simple to check to see if it matters.

Not in this case. The aiming might be off but the raycast for the bullet is done via 2 points in space without going through the camera.

@yaustar, I think I solved the problem. I switched places the variables from and to for raycasting, and seems it all worked. Need to make a large number of shots to understand whether my decision is true. And it seems to me that the boxes began to fly otherwise. :slightly_smiling_face:

Got it. Makes sense.