My wallrun in the character controller isnt working, how can i fix it?,My wallrun isn't working on the left side, how can I fix it?
So wallrunning on the right side works just fine, but the left side is broken. My code fires raycasts left and right to see if theres walls, and ifthere are it will wallrun. It uses a rigidbody to make sure that its physics work, so i freeze the position when the character wallruns. The controller is inside a child object. the void's code:
void Wallrun(RaycastHit Hit)
{
if (!HasWallran)
{
RB.constraints = RigidbodyConstraints.FreezePositionY;
LastWallNormal = Hit.normal;
RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
Wallrunning = true;
return;
}
else if (LastWallNormal.x - Hit.normal.x == 1 || LastWallNormal.x - Hit.normal.x == -1 || LastWallNormal.z - Hit.normal.z == 1 || LastWallNormal.z - Hit.normal.z == -1)
{
RB.constraints = RigidbodyConstraints.FreezePositionY;
LastWallNormal = Hit.normal;
RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
Wallrunning = true;
}
}
the code in Update:
if (Input.GetKeyDown(KeyCode.Space))
{
//jump
if (IsGrounded)
{
Jump();
return;
}
//wallruns
Ray left = new Ray(transform.parent.position, transform.parent.right * -2);
RaycastHit lefthit;
if (Physics.Raycast(left, out lefthit, 2))
{
Wallrun(lefthit);
}
else
{
RB.constraints = ~RigidbodyConstraints.FreezePosition;
}
Ray right = new Ray(transform.parent.position, transform.parent.right * 2);
RaycastHit righthit;
if (Physics.Raycast(right, out righthit, 2))
{
Wallrun(righthit);
}
else
{
RB.constraints = ~RigidbodyConstraints.FreezePosition;
}
}
if (Input.GetKeyUp(KeyCode.Space) || TImeLeftWallrun < 0)
{
if (Wallrunning)
{
RB.constraints = ~RigidbodyConstraints.FreezePosition;
if (TImeLeftWallrun > 0)
{
TImeLeftWallrun = MaxWallrunTime;
RB.velocity = new Vector3(RB.velocity.x, JumpPower / 2, RB.velocity.z);
}
Wallrunning = false;
}
}
I have more code than that, but this code is the relevant code to my issue.
,There is no error message. What is supposed to happen is the character controller which is in the head (child object) is supposed to make it so that if i press space next to a wall and I'm not on the ground it wall runs alongside other normal character controller things. My issue is that when I wallrun on the left side it doesn't freeze the rigidbody's Y coordinate. code: if (Input.GetKeyDown(KeyCode.Space)) { //jump if (IsGrounded) { Jump(); return; } //wallruns Ray left = new Ray(transform.parent.position, transform.parent.right -2); RaycastHit lefthit; if (Physics.Raycast(left, out lefthit, 2)) { Wallrun(lefthit); } else { RB.constraints = ~RigidbodyConstraints.FreezePosition; } Ray right = new Ray(transform.parent.position, transform.parent.right 2); RaycastHit righthit; if (Physics.Raycast(right, out righthit, 2)) { Wallrun(righthit); } else { RB.constraints = ~RigidbodyConstraints.FreezePosition; } }
void Wallrun(RaycastHit Hit)
{
if (!HasWallran)
{
RB.constraints = RigidbodyConstraints.FreezePositionY;
LastWallNormal = Hit.normal;
RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
Wallrunning = true;
return;
}
else if (LastWallNormal.x - Hit.normal.x == 1 || LastWallNormal.x - Hit.normal.x == -1 || LastWallNormal.z - Hit.normal.z == 1 || LastWallNormal.z - Hit.normal.z == -1)
{
RB.constraints = RigidbodyConstraints.FreezePositionY;
LastWallNormal = Hit.normal;
RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
Wallrunning = true;
}
}
oops... I forgot to save. Welp i guess the issue isnt there anymore, back to the old code XD
Your answer
![](https://koobas.hobune.stream/wayback/20220613060031im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody blocking raycasts 2D 0 Answers
Help with Time Crisis crosshair 0 Answers
Question on Peaper.Io ? 0 Answers