Trying to find a good method to deal with this very odd collision edge case. Google and the usual resources yielded no substantial advice on this matter.
This is less of a code query and more of a “how should I approach this” problem; Two wedges intersect to form a peak like so:
Ideally for a vertical cylindrical collider, moving up along one side should bring it up to the top, where it stays level until the bottom is no longer colliding with the peak, at which point the entire body descends. Both moving up and down the slopes works fine, but it’s around the peak where things get a little screwy…
I suspect the way I’m detecting collisions beneath the player is at fault here - a ring of 16 discrete points with another 16 to fill in the middle arranged in one of those funky Fibonacci patterns.
At the moment it’s finding whichever one of the points is the highest, and resolving an imaginary “ground” from said point. The main issue here is around the tip of the intersection, the thinner parts that do slip between the points cause confusion with this method, resulting in the slight but unpleasant jitter in the video.
I also have to point out that while I’m trying to refrain from using Roblox’s default collision detection and interaction, I’m not against falling back on it if no other alternative solutions are available. Any help would be much appreciated.
In the video you can probably make out a small jitter, which means the collider can’t accurately determine what the maximum height is. I’m trying to figure out how to get rid of it so movement near the peak is smooth and consistent.
I had the idea for a central downwards cast a while back, but in practice it isn’t really all that useful. The main goal here is to ensure that when the collider does reach the peak, so long as some part of the cylinder’s base is resting on that line/point, it maintains that height.
You could try using the spatial query API and scan in layers to find the upper height, ideally workspace:GetPartBoundsInBox with a 2D hitbox
You stick with your method of casting down an array of rays, then you use the spatial query to tweak the height upwards until it finds the physical upper-most point
You are right in that it is an expensive process, but the possibility of the true peak position being in between the checked layers still remains. This just makes the layers responsible for error and not the original downwards casts.
Then I suppose the only other solution would be to use Roblox physics that you tried to stray away from. Use a spring constraint that drops vertically relative to the player’s position, and use the contact point
Actually I don’t think you need a spring, a PrismaticConstraint should work since the physics engine would just eject any unanchored parts clipping inside one another to the nearest surface