I’m making a custom character controller, and I’m having issues with getting the player to jump because of how its made.
A basic rundown of how the movement works is:
The player shoots a ray below them constantly to check if there’s ground,
If there is ground, then (on the internal side) a Boolean called “grounded” is updated accordingly, and an AlignPosition constraint copies the player’s position, and offsets the Y by the player’s HipHeight (to keep them from falling over, and to keep them above ground.).
The issue with this approach is the fact that the player has issues with getting off the ground (Jumping, in-game mechanics like Bounce-pads, etc); the checks run too often to give the player a chance to get off the ground before the AlignPosition snaps them back down.
I can’t add a wait time either because the player would noticeably flicker up and down.
I’ve tried many ways to remedy this like putting in a check that sees if the “grounded” variable is true or false; dictating whether or not to update the AlignPosition, but since the ray is the one controlling that, the variable would always be true. (unless the player falls off a tall ledge, but we’re talking about jumping).
If anyone has ideas on what could help, please tell! thank you in advance!
I feel like doing that would be more trouble than it’s worth. Trust me, I’ve tried before.
I should’ve mentioned this before, but there are many ways to gain height in my game, bounce pads with varying heights, and objects that bounce the player up at a wide range of distances. I don’t think there’s a feasible way to measure every option of height-gaining-methods, and that’s when I realized that I needed another way.
TL;DR: doing that felt like a Band-aid fix that worked for a bit – but after a while – it was an un-optimal way to handle the problem.
It worked when jumping, but when the player gets back onto the ground they fall over.
Disabling the function that checks whether or not the player is on the ground causes the player to fall infinitely until it’s reenabled; but we don’t know when to reenable it because we don’t know when the player is grounded or in-air, since the function that detects that is disabled.
in short:
If we disable the function that checks if the player’s grounded, then we to take a shot-in-the-dark when trying to reenable it.
Is your game still using rigs with humanoids? What is with this goofy system and why do you need to do it like that
Just keep the raycast distance check on but just turn off align position
or if you’re still using humanoids you coulddddd try reading FloorMaterial but that sounds finicky as heck
Is this really the most optimal solution for your problem? Using an AlignPosition here feels like you are wildly overcomplicating what should be a simple problem. You want them to remain upright, and also keep their root part above ground, so why not instead of using an AlignPosition create an invisible collider part (or even a mesh, a pill shaped collider might be more optimal here).
This collider part would then have an AlignOrientation that keeps them upright without influencing the direction they are looking in, and since this collider part is what is touching the ground, the root part will appear to be in a normal location above the ground as long as the collider is the right size.
If the concern with this approach is hitboxes, you can set the collider’s CanQuery and CanTouch properties to false so it only influences physics.
It’s a Sonic Engine, so I need some way to keep the player on walls, roofs, etc.
Using an AlignPos contraint allows for this, and the other two uses.
I never mentioned this since I didn’t think it was important enough; because I didn’t really imagine that anyone would have an issue with the way I handled that stuff, since this is the first character controller I’ve made; I thought it was the norm.
It uses custom character models (the guys with actual bone deformation).
I do keep the raycast on, and disable the AlignPos, It’s actually been my current setup for a while until now; I misunderstood your statement since you said “system” and not part of it so thats on me .
Nevertheless, the issue is the fact that the Raycast checks if the player’s grounded, and before the player can get far enough off the floor to count as “un-grounded” (via jumping, and other in-game forms of getting air time); the ray reenables the AlignPos since the player is close enough to the floor to count as “grounded”.
This is partly because of the slight overshoot of the Raycast, this is to solve the issue of bouncing off slopes at high speeds, and to compensate for lower framerates and the inconsistencies that come with that.
I’m learning that I’m very unclear with my topics and that’s on me, I’ll try to mention more stuff🙁
I’d probably recommend giving the method I mentioned a try, but also throw in a VectorForce or similar constraint that simulates gravity in the direction they need to be grounded onto. You’re gonna have a way harder time getting results you actually like trying to force it using an AlignPosition than you would just letting the physics engine naturally do its thing,
But for a solution within your current implementation, what I’d think you may want to do is keep track of the state a bit more, when they’ve just jumped they would enter a “jumping” state, and then only once the upwards momentum has stopped and they start falling, enter a “falling” state which then allows the raycast to be enabled again.