Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
avatar image
0
Question by brlan10 · Oct 19, 2016 at 01:40 AM · rigidbody2daddforcefriction

Jumping is slightly faster than running due to friction

I have a 2D character controller that uses addForce to run and sets a clamp to limit run speed. It all works great on the ground.

But - due to friction, my character moves slightly faster on the x axis while airborne. So for example, my x velocity will be 13.8 on land and 14.0 in the air. I need tips on how I can prevent this. I'd like them both to be exactly the same (like in mario, or any other platformer worth its weight in salt).

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by andzq · Oct 19, 2016 at 01:49 AM

just apply the friction while u´re not holding a movement key.

Comment
Add comment · Show 11 · 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
avatar image brlan10 · Oct 19, 2016 at 05:35 PM 0
Share

This worked out for me, but a warning to others who are looking to attempt changing friction via script in 2D unity - it is buggy and needs a workaround. I finally found the workaround here:

http://answers.unity3d.com/questions/949087/changing-friction-from-code-not-working-2d.html

avatar image Naphier · Oct 20, 2016 at 04:10 AM 0
Share

I always just do it while the player is in the air (i.e. not grounded). This way a release of the key doesn't slow down the player's sliding on the ground and you keep that nice mario effect.

avatar image awsapps Naphier · Mar 22 at 09:01 AM 0
Share

Can you explain how did you apply the friction on the air? Do you tweak the drag/angular drag on air?

avatar image brlan10 · Oct 20, 2016 at 12:47 PM 0
Share

@ Naphier

The way I'm doing it, the player is at 0 friction while running. So I HAVE to change friction while he's on the ground, otherwise he will slide for eternity. Even with friction turned back on, he doesnt stop immediately though. It is working quite well.

I wouldn't even have to fiddle with the friction at all if he wasn't faster in the air than on the ground.

avatar image Naphier brlan10 · Oct 20, 2016 at 05:06 PM 0
Share

I see, I wouldn't do 0 friction when running, just apply enough force so that my running looks correct. But everyone does this a little different. I'm not sure why he would move faster in the air though, maybe he has a physic material with friction too (or the ground does)? When my players are in the air they don't move faster, but they can accelerate because I'm still using AddForce while they're in the air, but I just have the script double their drag while in the air and it's not problem. Looks great too.

avatar image brlan10 Naphier · Oct 20, 2016 at 07:15 PM 0
Share

I see. Yeah there is no drag applied to my player, so the player is always faster in the air, because friction comes into play on the ground. You slowed him in the air to fix it, I sped him up on the ground by removing friction while in motion. I will fool around with your solution and see if that works better for me, but right now my movement works great.

Show more comments
Show more comments
avatar image Naphier brlan10 · Oct 20, 2016 at 07:40 PM 0
Share

Not sure if it really is though. If you think about it, we should probably strive to model after real life physics as much as possible. So really the ground should have a physic material and the player too, these would create the normal ground drag, but while in the air we shouldn't be applying any new force, or if we do the force should be much smaller than the movement force. But it's a tough one because game physics (espt 2d platformers) are not very realistic. So the simplest solution wins, or the one you think of at the time!

avatar image brlan10 Naphier · Oct 20, 2016 at 08:22 PM 0
Share

Right its not so much realism I'm going for as it is robust implementation that will hold up in all kinds of conditions down the line. Zeroing friction while in motion just doesn't sit well with me in that regard.

Btw all colliders have a default friction of 0.4 if there is no material attached, so don't worry about adding a material to everything that touches your character.

Show more comments

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

58 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

Related Questions

Character instantly jumps instead of smoothly gaining altitude 3 Answers

Why doesn't rigidbody2D.AddForce(-5, 2); work? 1 Answer

Add force once when object is created 1 Answer

Rigidbody2D.AddForce fails to add force 0 Answers

Jump problem 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