• 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
1
Question by Draze · Dec 29, 2015 at 10:49 PM · movement2d-platformervelocity2d-physics2dmovement

2D Velocity movement on slope hops when moving left/right

I'm working on a 2D platformer. I have run into an issue with straight slopes and left/right movement. I am controlling movement based on velocity to give snappy controls. The problem is that when going down a slope, if you go from 0 to 1 it gives a burst of velocity that makes it look like you hop initially then continue down the slope at a normal rate. It also hops a bit when moving just left.

Here is a video that shows the issue

Here is the relevant code. dirAxis is a 1,0,-1 variable based on my touch input. moveSpeed is a constant int.

  void FixedUpdate ()
     {
         rigid2d.velocity = new Vector2(dirAxis * moveSpeed, rigid2d.velocity.y);
         dirAxis = 0;
     }

A solution I am currently working with is this, and it works except for it's unintended effects on grounding while in the air (e.g. if I hop on a one directional platform I all of a sudden lose the ability to continue going up and jitter through the "ground" collider. This obviously is not the best correct solution, but it does work on the ground.

 void FixedUpdate ()
 {
     Vector2 moveVec = Vector2.zero;
     if (!isInAir)
         moveVec = dirAxis * moveSpeed * transform.right;
     else
         moveVec = new Vector2(dirAxis * moveSpeed, rigid2d.velocity.y);

     rigid2d.velocity = moveVec;
     dirAxis = 0;
 }

Things to note:

-The Unity 2D standard character controller (Robot dude) has this same bug when his movement is set to a high enough speed (~15-20) (also uses velocity movement so I'm not surprised.

-Setting the gravity to a higher setting while grounded will not work for me (already tried it and it messes with my other physics).

-My character is rotating based on the ground he is on, but this issue persists even if his z-axis is 'frozen'

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.

Follow this Question

Answers Answers and Comments

34 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

Related Questions

Please help with infinite gravity swapping problem 0 Answers

How to cancel the force caused by collision? So the player is not pushed away when it hits a corner? 0 Answers

How do I assign a velocity to an object on only 1 axis? 1 Answer

How to fix minor jitter/stutter when moving a 2D character using physics in FixedUpdate() 0 Answers

Move NPC on triggerEnter 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