Raycasts work great for levels consisting of flat ground but it doesn’t cut it for my terrain levels which consists of uneven terrain, so I’m gonna have to find another solution for those.
Spherecasting would solve this but I’m afraid that it will be very costly to run those repeatedly. I would perform a raycast straight down to check if the terrain is flat, and if it’s not I’d follow it up with a spherecast. The problem is that I would want to do a second spherecast at the next position to decide whether or not to disable gravity (assuming the first spherecast hit, aka grounded); if the second spherecast doesn’t hit anything using the distance from the first one then gravity will be enabled, otherwise not.
Another solution might be to use a box collider for the player instead of a capsule which would hopefully make the raycasts reliable enough to work in rough terrain. Sounds much cheaper but I’m not sure if it will be sufficient.
I’m using a rigidbody and not a character controller.
I think what it does is it makes the skeleton adapt to difficult terrain, I don’t know enough about that one though as I haven’t researched it properly yet. If you want to do climbing and vaulting etc. though you’ll be needing to look at Inverse Kinematics as well which I have looked at, that lets you use empties on a skeleton to attach your character to objects allowing them pull themselves up and so on, it’s also used for attaching weapons or other objects to hands and stuff.
Anyway, that’s what I’d recommend having a look at if you want to try and fix it properly, others might be able to tell you more.
I haven’t ran benchmarks, mostly cause I don’t really know how to do it. Currently between 2-10 if the player is moving, and most often only 2 are needed. With spherecasts I would use 2 each frame of movement.
People on forums have said they are more expensive but no one posted any benchmarks so I probably should learn how to do some myself.
Good to hear it’s not that expensive, how many do you use per frame btw?
I do not think you are not developing efficiently. You do not understand much about optimisation.
Seeking to optimise that when spherecast and raycast are essentially the same thing perf wise - is insanity. I’m probably going to have to make the default response something like “please post profiler shots!”
So can you please just make your game, then come back when and if you actually ever have a problem - don’t optimise right now