- Home /
Question by
AdrellaDev · Aug 24, 2018 at 01:23 AM ·
player movementcharacter controllercharacter movementwallswall collision
Wall Running on Curved Surfaces
Hello! I am currently trying to implement a wall running mechanic in an FPS game. I currently have it working with smooth surfaces/walls but I am having a hard time making it work for curved surfaces. Here is the code I have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class WallRun : MonoBehaviour {
private bool isWallR = false;
private bool isWallL = false;
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 (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")
{
isWallL = true;
isWallR = false;
jumpCount += 1;
rb.useGravity = false;
StartCoroutine(afterRun());
}
}
}
IEnumerator afterRun ()
{
yield return new WaitForSeconds(1.0f);
isWallL = false;
isWallR = false;
rb.useGravity = true;
}
}
Like I said, this works for smooth, flat walls but I need help with the player following curved walls too. Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612173400im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best practice when creating character / player control scripts? 2 Answers
Movement correct to wasd Help 2 Answers
Lock Character to Z axis. 1 Answer