- Home /
Question by
Spezzdidly13 · Aug 13, 2018 at 06:23 PM ·
c#physicsprogramming
How to convert this to up and down wall run?
I have a script I found on the internet that makes a first person controller run right and left on a wall. I was wondering if anyone knew how to make it up and down rather than left and right. I tried changing the variable names and the transfrom but it didn't seem to work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class WallRun : MonoBehaviour {
private bool isWallR;
private bool isWallL;
private RaycastHit hitR;
private RaycastHit hitL;
private int jumpCount =0;
private RigidbodyFirstPersonController cc;
private Rigidbody rb;
void Start () {
cc = GetComponent<RigidbodyFirstPersonController> ();
rb = GetComponent<Rigidbody> ();
}
void Update () {
if (cc.Grounded) {
jumpCount = 0;
}
if (Input.GetKeyDown (KeyCode.E) && !cc.Grounded && jumpCount <= 1) {
if (Physics.Raycast (transform.position, transform.right, out hitR, 1)) {
if (hitR.transform.tag == "Wall") {
isWallR = true;
isWallL = false;
jumpCount += 1;
rb.useGravity = false;
StartCoroutine (afterRun ());
}
}
} if (Physics.Raycast (transform.position, -transform.right, out hitL, 1)) {
if (hitL.transform.tag == "Wall") {
isWallR = false;
isWallL = true;
jumpCount += 1;
rb.useGravity = false;
StartCoroutine (afterRun ());
}
}
IEnumerator afterRun () {
yield return new WaitForSeconds (0.5f);
isWallL = false;
isWallR = false;
rb.useGravity = true;
}
}
}
Comment