Download

Raytrace not generating hits on skysphere?

I am using ray tracers to direct projectiles from my gun barrel to the crosshairs and it’s working almost perfectly. The only problem is when I aim at the sky (sky-sphere) the raytrace does not collide with it for some reason, and thus I cannot shoot at the sky, only at the landscape and objects. Can anyone tell me why this might be? I know my rays go far enough and I’ve tried giving the sky-sphere BlockAll collision and messed around with a bunch of collision related options in the details panel with no luck. At this point I’m out of ideas and would appreciate any help.

This thread from month or two ago is somewhat relevant, but they couldn’t figure it out either, thanks.

Maybe because skysphere has no collision. But you doing it wrong.

When you detect that raytrace does not collide ie. hits nothing. Check vector direction it is pointing to. If that vector Z is positive (or calculate dot product between 0,0,1 and normalized trace direction, and this is less than 1). This way you can check if raytrace is pointing upwards (dot product is better here), so if its upwards and hits nothing, you fake collision point by normalising direction raytrace, then multiply it by for eg 10000, resulting location would be somewhere quite far on the sky. Use that for further calculations.

Doing collision sphere that can be hit from inside is bit messy. Unlike sphere collision from outside (which is easiest case), same collision, but from inside is worst.

Ok, I get the gist of what you’re saying, there’s a slight problem though. If I start by trying to shoot at the sky, I can detect that there is no hit. But if I shoot an object or something with collision then shoot at the sky, the raytrace still points to the last hit result detected. So I would end up aiming at the sky and shooting at the ground, for instance.

EDIT: nvm figured it out, thanks chief