- Home /
Wallrunning backwards
I'm writing a script for wallrunnning. Basically, when you hit the wall, you can't move sideways and your gravity is turned off until you are either too slow, jump off or run off the wall. However, when I run on a wall that had been turned around (Y=-180), my character runs in the opposite direction on the horizontal axis, vertical is still fine.
I want to be able to run on both sides of the walls in both directions.
My main wallrunning part:
if(WallRunning == true) {
PlayerRB.drag = 1;
WallPointReg = CamTurn.transform.InverseTransformPoint(SlidePointReg);
if(WallRunTiltTimer == 0) {
if(WallPointReg.x > 0) {
if(CamTurn.transform.localEulerAngles.z < 7.5f) {
CamTurn.transform.Rotate(0, 0, 1.25f * Camera.GetComponent<CamControl>().TurnSpeed * 7.5f * Time.deltaTime, Space.Self);
}
if(CamTurn.transform.localEulerAngles.z > 7.5f) {
CamTurn.transform.localRotation = Quaternion.Euler(0, 0, 7.5f);
}
}else {
if(CamTurn.transform.localEulerAngles.z > 352.5f || CamTurn.transform.localEulerAngles.z == 0) {
CamTurn.transform.Rotate(0, 0, 1.25f * Camera.GetComponent<CamControl>().TurnSpeed * -7.5f * Time.deltaTime, Space.Self);
}
if(CamTurn.transform.localEulerAngles.z < 352.5f) {
CamTurn.transform.localRotation = Quaternion.Euler(0, 0, 352.5f);
}
}
}
// if(Vector3.Distance(transform.position, SlidePointReg) > 1) {
// }
PlayerRB.useGravity = false;
float VerticalWall = Input.GetAxis("Vertical") * Speed * Time.deltaTime;
if(WallSpeedLimit > 12.5f) {
WallSpeedLimit = 12.5f;
}
WallSpeed = CharVel.magnitude;
if(CharVel.magnitude < WallSpeedLimit) {
WallSpeedLimit += ((WallSpeedAcc * Camera.transform.rotation.x / 90) - WallSpeedDeAcc) * Time.deltaTime;
if(WallPointReg.x > 0) {
if(transform.position.y >= WallRunOri + WallRunYLimit && Camera.transform.rotation.x < 0) {
PlayerRB.velocity += new Vector3(0, 0, (transform.TransformDirection(WallLocalVel) * VerticalWall).z);
}else {
PlayerRB.velocity += transform.TransformDirection(WallLocalVel) * VerticalWall;
}
}else {
if(transform.position.y >= WallRunOri + WallRunYLimit && Camera.transform.rotation.x < 0) {
PlayerRB.velocity += new Vector3(0, 0, (transform.TransformDirection(WallLocalVel) * -VerticalWall).z);
}else {
PlayerRB.velocity += transform.TransformDirection(WallLocalVel) * VerticalWall;
}
}
Debug.DrawRay(transform.position, transform.TransformDirection(WallLocalVel), Color.red);
}
float WallSpeedControlTemp = CharVel.magnitude;
if(WallSpeedControlTemp < WallSpeedControl - 1) {
PlayerRB.velocity = (PlayerRB.velocity / WallSpeedControlTemp) * WallSpeedControl;
WallSpeedControl = WallSpeedControlTemp;
}else {
WallSpeedControl = WallSpeedControlTemp;
}
}
if(CharVel.magnitude < WallRunSpeedMin && WallTimeMin == 0 && WallRunning == true) {
WallRunning = false;
PlayerRB.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
Debug.Log("Too slow. " + CharVel.magnitude);
PrevWall = SlideGround;
}
if(WallPointReg.x > 0) {
if(WallRunning == false && CamTurn.transform.localRotation.z > 0 && Camera.GetComponent<CamControl>().LookingBack == false) {
CamTurn.transform.transform.Rotate(0, 0, 1.25f * Camera.GetComponent<CamControl>().TurnSpeed * -7.5f * Time.deltaTime, Space.Self);
}
if(WallRunning == false && CamTurn.transform.localRotation.z < 0) {
CamTurn.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}else {
if(WallRunning == false && CamTurn.transform.localRotation.z < 0 && Camera.GetComponent<CamControl>().LookingBack == false) {
CamTurn.transform.transform.Rotate(0, 0, 1.25f * Camera.GetComponent<CamControl>().TurnSpeed * 7.5f * Time.deltaTime, Space.Self);
}
if(WallRunning == false && CamTurn.transform.localRotation.z > 0) {
CamTurn.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
make Character Run up walls? 0 Answers
How to solve object itself movement? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers