• 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 serg06 · Apr 16, 2017 at 06:34 PM · 2d2d-platformerrigidbody2dvelocityfriction

2D player slower on ground than in air

Hi guys. I'm making a 2D platformer and my player is slower on the ground than in the air for some reason.

When I'm in the air, my speed steadily approaches my maxSpeed, 10.0, however on the ground it fluctuates between 6.8 and 7.0. This is how I add speed (maxSpeed and speed are constants):

 float xaxis = Input.GetAxisRaw ("Horizontal");
 rb.AddForce (new Vector2 (xaxis, 0) * (Mathf.Max (maxSpeed - Mathf.Abs (rb.velocity.x), 0)) * speed);

I tried following http://answers.unity3d.com/questions/1258619/jumping-is-slightly-faster-than-running-due-to-fri.html and disabling player's friction when not holding movement key, but it didn't change anything:

 if (xaxis == 0) {
     bc.sharedMaterial.friction = defaultFriction;
     rb.sharedMaterial.friction = defaultFriction;
 } else {
     bc.sharedMaterial.friction = 0;
     rb.sharedMaterial.friction = 0;
 }

Player settings (player material just has 0.5 friction)

image

Ground settings (ground material also has 0.5 friction)

image

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
0

Answer by serg06 · Apr 17, 2017 at 06:31 PM

Update: After replacing my addForce with velocity+=, it's still bumpy between 8.0 and 8.1, but it feels much more natural.

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.

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

140 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

Related Questions

Climbing code problem (2d physic). 0 Answers

Best ground 2D ground check strategy? How to detect if a object is touching the top of a layer? 0 Answers

Player randomly stops moving 1 Answer

RigidBody2D velocity randomly drops to zero 1 Answer

Adding velocity to an object in a brick breaker game 0 Answers

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