Hi im realy, realy new so i try to master some stuff and it takes very long for me.
I made a Raycast check to detect the walls and it works fine.
Like this:
Wall run starts:
Player (Is moving 45° to the wall)
…\
…\
…\
Wall to wall run and it works fine
.
.
My Problem is:
How can i Rotate my player from this \ to this – ?
Like 45° away from the wall so the Player is in this direction:
.
.>
Player ---->
Wall
.
.
RaycastHit doWallRunCheck(){
Ray rayRight = new Ray(transform.position, transform.TransformDirection(Vector3.right));
Ray rayLeft = new Ray(transform.position, transform.TransformDirection(Vector3.left));
RaycastHit wallImpactRight;
RaycastHit wallImpactLeft;
bool rightImpact = Physics.Raycast(rayRight.origin, rayRight.direction, out wallImpactRight, 0.45f);
bool leftImpact = Physics.Raycast(rayLeft.origin, rayLeft.direction, out wallImpactLeft, 0.45f);
if (Input.GetKey("w") && Input.GetAxis ("Horizontal") == 0f && rightImpact && Vector3.Angle
(transform.TransformDirection (Vector3.forward), wallImpactRight.normal) > 105f) {
//Debug.DrawRay (rayRight.origin, rayRight.direction * 10, Color.red);
rightWallRun = true;
startWallRun = 1;
return wallImpactRight;
}
else if (Input.GetKey("w") && Input.GetAxis ("Horizontal") == 0f && leftImpact && Vector3.Angle
(transform.TransformDirection(Vector3.forward), wallImpactLeft.normal) > 105f) {
wallImpactLeft.normal *= -1;
leftWallRun = true;
startWallRun = 1;
return wallImpactLeft;
}
else {
rightWallRun = false;
leftWallRun = false;
return new RaycastHit();
}
}
//Key combo conditions
if (leftWallRun) {
if (startWallRun >= 1 && canWallRun) {
if (Input.GetKey ("w") && Input.GetAxis ("Horizontal") == 0f) {
startWallRun = 2;
if (Input.GetButton ("Jump")) {
startWallRun = 3;
if (startWallRun >= 3) {
startWallRunMoveLeft++;
startWallRun = 0;
}
}
}
}
}
//left wall run starts to move
if (startWallRunMoveLeft >= 1){
//45° left will come there...
}
Please help me i realy dont get it now!
PS: If some need a raycast to detect walls to finaly wall run, this one works fine for me.