Hello! I’ve been practicing some time making a 3D platforming game, including some basic physics.
I’m trying to do a wall jump mechanic. Basically, if the object in question detects that there is ground above him, if I press the jump button it will rotate to match the ground’s normal.
The problem I’ve got it’s that when I try to do this, the direction also changes, and starts to walk in the opposite direction that I want the object to move.
YouTube video that shows the problem
private void SlopeRotation()
{
if (isGrounded || !rotateToGround)
{
if (isGrounded || isJumping)
{
waitAndRotate = waitRotationTime;
}
groundNormal = ray.normal;
slopeRotation = Quaternion.FromToRotation(transform.up, groundNormal) * transform.rotation;
transform.rotation = slopeRotation;
//rb.MoveRotation(slopeRotation);
if ((transform.rotation == slopeRotation) && !rotateToGround)
{
Debug.Log(groundNormal);
rotateToGround = true;
}
Debug.DrawRay(ray.point, ray.normal * 2, Color.blue, 1);
}
else if (!isGrounded && !isJumping)
{
if (waitAndRotate <= 0f)
{
rb.MoveRotation(Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0f, transform.rotation.eulerAngles.y, 0f), slopeRotationSpeed * Time.deltaTime));
}
else
{
waitAndRotate -= Time.deltaTime;
}
}
}