• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

88 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

3D RPG - Player movement - He automatically finds the fastest way and goes around everything. How to limit his movement? 1 Answer

how to make 2d character jump? 0 Answers

How to prevent character controller from tipping when moving along terrain? 1 Answer

How to cut the leg / arm of a character 1 Answer

Player keeps flying up 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges