Hello,
I have a wallrunning script which fires Raycasts directly left, directly right, and some diagonals. Upon hitting a wall, that Hit is returned as RaycastHit wallrunWall;
, and, should no wall be detected, wallrunWall = new RaycastHit();
, as shown here (removed some things that shouldn’t matter, and is in FixedUpdate):
if ( (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.left), out wallrunWall, WallRunDetectionRange) ||
Physics.Raycast(transform.position, transform.TransformDirection(RaycastLeftDiagonal.normalized), out wallrunWall, WallRunDetectionRange)) && testingForWallRunLeft) {
wallrunningLeft = true;
} else {
wallrunWall = new RaycastHit();
wallrunningLeft = false;
}
if ( (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out wallrunWall, WallRunDetectionRange) ||
Physics.Raycast(transform.position, transform.TransformDirection(RaycastRightDiagonal.normalized), out wallrunWall, WallRunDetectionRange)) && testingForWallRunRight) {
wallrunningRight = true;
} else {
wallrunWall = new RaycastHit();
wallrunningRight = false;
}
Here, when Debug.Log(wallrunWall.normal);
for both left and right sides, I receive the proper normal vectors. However, in my Update method, where I calculate the parallel to the wall for wallrunning (shown here), wallrunWall is correct on the right side, but undefined on the left side.
inputVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// CHANGE VELOCITY BY MOVEMENT INPUT
if (!wallrunningLeft && !wallrunningRight) {
velocity = new Vector3(inputVector.x * PlayerMoveSpeed, velocity.y, inputVector.z * PlayerMoveSpeed);
} else {
// weird vector stuff
wallParallel = Vector3.Cross(wallrunWall.normal, Vector3.up);
if (wallrunningRight) {
tempVelocity = new Vector3(wallParallel.x * -inputVector.z * PlayerWallrunSpeed, 0, wallParallel.z * -inputVector.z * PlayerWallrunSpeed);
} else {
tempVelocity = new Vector3(wallParallel.x * inputVector.z * PlayerWallrunSpeed, 0, wallParallel.z * inputVector.z * PlayerWallrunSpeed);
}
velocity = transform.InverseTransformDirection(tempVelocity);
}
The result effect is that wallrunning works perfectly on the right side, but the player doesn’t move when on the left side. I’ve been stuck on this for a while, and any help is greatly appreciated!
Thanks