Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by RayKatz · Feb 03, 2014 at 05:48 PM · movementphysicsrigidbodycharacter

How to handle walls with my FirstPersonCharacter?

I am using a rigidbody to control my character. I am setting its velocity based an the player input, and it works pretty great (it's similiar to the one in the new Sample Assets from Unity). Only problem is: If my character jumps against a wall and keeps moving in the direction of the wall, the character isn't falling. Any ideas how I could solve this?

Comment
Add comment · Show 3
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 Nanobrain · Feb 04, 2014 at 05:42 AM 0
Share

We will need to see some code please. Hard to know how you are implementing your character controller exactly. No code, no context.

avatar image RayKatz · Feb 04, 2014 at 05:42 PM 0
Share

I use a state machine to handle movement, but I wrote it as a c# script to show what it does:

 public class Pseudo$$anonymous$$ove : $$anonymous$$onoBehaviour {
 
     Vector3 input;
     float verticalVelocity = 0.0f;
     float speed = 10.0f;
     float jumpStrenght = 8f;
 
     // Update is called once per frame
     void FixedUpdate () {
         input = new Vector3(Input.GetAxis("Horizontal")*speed,0,Input.GetAxis("Vertical")*speed);
         input = transform.TransformDirection(input);
 
         verticalVelocity = rigidbody.velocity.y;
 
         if(Input.GetButtonDown("Jump"))
         {
             verticalVelocity += jumpStrenght;
         }
 
         rigidbody.velocity = input + Vector3.up * verticalVelocity;
         rigidbody.AddForce(0f,-9.81f,0f);
     }
 }

I left ground checking out, so it doesnt distract. $$anonymous$$y main problem is walls and ledges, where the character just keeps getting stuck until moved in another direction.

avatar image RayKatz · Feb 04, 2014 at 06:17 PM 0
Share

Woooooow I am an idiot. The problem was friction on the physics material that let the charcter getting stuck on things. I'm going to go cry now... Thanks anyway!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nanobrain · Feb 04, 2014 at 06:32 PM

Since your character is a ridgidbody, why not just let the built in code handle the fall for you. Set your ridgidbody to be effected by gravity in the editor. Then when

 if(Input.GetButtonDown("Jump"))
 {
     ridgidBody.AddForce(0f, jumpSpeed, 0f);
 }

Then remove this

  rigidbody.velocity = input + Vector3.up * verticalVelocity;
 rigidbody.AddForce(0f,-9.81f,0f);
Comment
Add comment · Share
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

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

19 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

Related Questions

Character controller jittering up and down 2 Answers

Ground clamping a rigidbody on slope 1 Answer

How not to make a RigidBody not go into ground when tilted foward? 1 Answer

Player slows down when hitting an incline 0 Answers

Click to move a character in a terrain 1 Answer


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