Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
avatar image
0
Question by Verse_NOVA · May 02 at 01:49 AM · rigidbodyraycasting

My wallrun in the character controller isnt working, how can i fix it?,My wallrun isn't working on the left side, how can I fix it?

So wallrunning on the right side works just fine, but the left side is broken. My code fires raycasts left and right to see if theres walls, and ifthere are it will wallrun. It uses a rigidbody to make sure that its physics work, so i freeze the position when the character wallruns. The controller is inside a child object. the void's code:

 void Wallrun(RaycastHit Hit)
     {
         if (!HasWallran)
         {
         RB.constraints = RigidbodyConstraints.FreezePositionY;
         LastWallNormal = Hit.normal;
         RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
         Wallrunning = true;
         return;
         }
         else if (LastWallNormal.x - Hit.normal.x == 1 || LastWallNormal.x - Hit.normal.x == -1 || LastWallNormal.z - Hit.normal.z == 1 || LastWallNormal.z - Hit.normal.z == -1)
         {
         RB.constraints = RigidbodyConstraints.FreezePositionY;
         LastWallNormal = Hit.normal;
         RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
         Wallrunning = true;
         }
     }

the code in Update:

 if (Input.GetKeyDown(KeyCode.Space))
         {
             //jump
             if (IsGrounded)
             {
                 Jump();
                 return;
             }
             //wallruns
             Ray left = new Ray(transform.parent.position, transform.parent.right * -2);
             RaycastHit lefthit;
             if (Physics.Raycast(left, out lefthit, 2))
             {
                 Wallrun(lefthit);
             }
             else
             {
                 RB.constraints = ~RigidbodyConstraints.FreezePosition;
             }
             Ray right = new Ray(transform.parent.position, transform.parent.right * 2);
             RaycastHit righthit;
             if (Physics.Raycast(right, out righthit, 2))
             {
                 Wallrun(righthit);
             }
             else
             {
                 RB.constraints = ~RigidbodyConstraints.FreezePosition;
             }
         }
         if (Input.GetKeyUp(KeyCode.Space) || TImeLeftWallrun < 0)
         {
             if (Wallrunning)
             {
                 RB.constraints = ~RigidbodyConstraints.FreezePosition;
                 if (TImeLeftWallrun > 0)
                 {
                     TImeLeftWallrun = MaxWallrunTime;
                     RB.velocity = new Vector3(RB.velocity.x, JumpPower / 2, RB.velocity.z);
                 }
                 Wallrunning = false; 
             }
         }

I have more code than that, but this code is the relevant code to my issue.

,There is no error message. What is supposed to happen is the character controller which is in the head (child object) is supposed to make it so that if i press space next to a wall and I'm not on the ground it wall runs alongside other normal character controller things. My issue is that when I wallrun on the left side it doesn't freeze the rigidbody's Y coordinate. code: if (Input.GetKeyDown(KeyCode.Space)) { //jump if (IsGrounded) { Jump(); return; } //wallruns Ray left = new Ray(transform.parent.position, transform.parent.right -2); RaycastHit lefthit; if (Physics.Raycast(left, out lefthit, 2)) { Wallrun(lefthit); } else { RB.constraints = ~RigidbodyConstraints.FreezePosition; } Ray right = new Ray(transform.parent.position, transform.parent.right 2); RaycastHit righthit; if (Physics.Raycast(right, out righthit, 2)) { Wallrun(righthit); } else { RB.constraints = ~RigidbodyConstraints.FreezePosition; } }

 void Wallrun(RaycastHit Hit)
     {
         if (!HasWallran)
         {
         RB.constraints = RigidbodyConstraints.FreezePositionY;
         LastWallNormal = Hit.normal;
         RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
         Wallrunning = true;
         return;
         }
         else if (LastWallNormal.x - Hit.normal.x == 1 || LastWallNormal.x - Hit.normal.x == -1 || LastWallNormal.z - Hit.normal.z == 1 || LastWallNormal.z - Hit.normal.z == -1)
         {
         RB.constraints = RigidbodyConstraints.FreezePositionY;
         LastWallNormal = Hit.normal;
         RB.velocity = new Vector3(RB.velocity.x, 0, RB.velocity.z);
         Wallrunning = true;
         }
     }
Comment
Add comment · Show 1
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
avatar image Verse_NOVA · Apr 30 at 08:51 PM 0
Share

oops... I forgot to save. Welp i guess the issue isnt there anymore, back to the old code XD

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.

Follow this Question

Answers Answers and Comments

236 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 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 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

Help with Time Crisis crosshair 0 Answers

Rigidbody blocking raycasts 2D 0 Answers

A way to make the player get punished when standing still? 0 Answers

Every GameObject that has a rigidbody, won't stay at Z 0 and I don't know why 0 Answers

Torque rigidbody toward desired rotation on two axes ignoring Y axes? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges