Replicate Krunker slide hop movement
I've got a working (but not quite right) script that I cant seem to get the sliding of my character correct. I am aiming to get the sliding the same as it is in Krunker.io.
The current issues I have is that when I slide and rotate my player at the same time my player continues its velocity in the original direction (so the ground feels slippery). I have added counter movements to try and stop that and by doing that it completely stops or slows down the player while sliding so I added more force forwards to stop that. Problem is I cant have to much counter of either one or I accelerate the slide way too fast, or I still slide off to the side and not the direction I want to fully go in. What can I do to change this?
Here is my code -
private void StartCrouch()
{
transform.localScale = crouchScale;
if (rb.velocity.magnitude > 0.5f)
{
if (grounded)
{
if (stopSlide == false)
{
rb.AddForce(orientation.transform.forward * slideForce, ForceMode.Force);
stopSlide = true;
}
if (localVelocity.x < -1) // Add force against Left
{
rb.AddForce(orientation.transform.right * (sideSlideForce + (-localVelocity.x * changeDirWhenSlideSpeedMultiplier)), ForceMode.Force);
rb.AddForce(orientation.transform.forward * (sideSlideForce + (-localVelocity.x * changeDirWhenSlideSpeedMultiplier)), ForceMode.Force);
}
else if (localVelocity.x > 1) // Add force against Right
{
rb.AddForce(-orientation.transform.right * (sideSlideForce + (localVelocity.x * changeDirWhenSlideSpeedMultiplier)), ForceMode.Force);
rb.AddForce(orientation.transform.forward * (sideSlideForce + (localVelocity.x * changeDirWhenSlideSpeedMultiplier)), ForceMode.Force);
}
if (localVelocity.z < -1)
{
curSideForce = orientation.transform.forward * (sideSlideForce * (-localVelocity.z * changeDirWhenSlideSpeedMultiplier));
rb.AddForce(orientation.transform.forward * (sideSlideForce * (-localVelocity.z * changeDirWhenSlideSpeedMultiplier)), ForceMode.Force);
}
}
}
}
Comment