I’m making web swinging in my Spider-Man game, but I’m having trouble trying to get a point for the player to swing off of. Making multiple swing points on the buildings would also be inefficient, so I want to use raycasting.
As you can see, the green lines are raycasts. Then, the game detect which points were intersected and will pick which of those points is the best swing point. How would I go upon this?
My only issue with this system, is what if there is a thin bar or beam that is the only swing point? Since there are only 6-8 raycasts, it’s going to be very hard for the game to detect that slim beam to swing off and the ray will most likely just miss right past it. I was thinking just trying to cast infinite points in front of the player to find the best swing point, instead of just like 8.
You could use shape casts. These are like raycasts but they’re thick, so they can detect even thin things. I’m not sure if they support growing cones though, because without cone casts there would be gaps as the distance increases.
I usually see people do this with either manually placed swing points/lines (probably too much work) or using simplified geometry (e.g. buildings are either boxes, spheres, or lines).
With simplified geometry, you only need to calculate the best point on each line/circle (or surfaces too, depending on if you include those). You can also use filtering to only need to calculate for near-by geometry. Doing geometry/linear math is pretty fast so even with a few thousand lines/surfaces it can be done in reasonable time.
An algorithm for picking the “best” swing point is more detailed though, and depends on your desired gameplay and the swinging physics you want to use.