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 /
avatar image
0
Question by TomatJuice · Jul 22, 2020 at 12:53 AM · rigidbody2dvelocityjumpphysics2d

Velocity not updating object position

In a plat-former game I am making I have a player controller that how a jump method in it. The velocity does get changed, I can see it in the info tab on the Rigidbody2D, but the position does not move with it. My Rigid-body is set to dynamic, the mass is 1, there is no drag of any kind, and it's positions are not constrained, as rb.MovePosition works. Here is my player controller code.

     public GameObject player;
     private Rigidbody2D _rb;
 
     public float speed;
 
     public float jumpForce;
     public float fallMultiplier = 2.5f;
     public float lowJumpMultiplier = 2f;
     private bool _isJumping = false;
     private bool _grounded = false;
 
     private Vector2 _movement;
 
     private void Start()
     {
         _rb = player.GetComponent<Rigidbody2D>();
     }
 
     void Update()
     {
         GetInputs();
     }
 
     private void FixedUpdate()
     {
         Move();
         Jump();
     }
 
     void GetInputs()
     {
         _movement.x = Input.GetAxis("Horizontal");
 
         if (Input.GetButtonDown("Jump") && _grounded)
         {
             _isJumping = true;
             _grounded = false;
             print("Jump");
         }
     }
 
     void Move()
     {
         _rb.MovePosition(_rb.position + _movement * speed * Time.deltaTime);
     }
 
     void Jump()
     {
         if (_isJumping)
         {
             _rb.velocity = Vector2.up * jumpForce;
         }
 
 
         if (_rb.velocity.y < 0)
         {
             _rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
         }
         else if (_rb.velocity.y > 0 && !Input.GetButton("Jump"))
         {
             _rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.deltaTime;
         }
     }
 
     private void OnCollisionEnter2D(Collision2D collision)
     {
         _grounded = true;
         _isJumping = false;
     }

 
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 davidcox70 · Jul 22, 2020 at 05:52 AM

I think don't use velocity to make your jump. Use AddForce instead. The docs generally recommend that we don't write to velocity.

Different subject: You are using time.deltaTime in a fixed update routine. Rather use time.fixedDeltaTime. This is because deltaTime gives you the duration of an update() frame and fixedDeltaTime gives you the duration of a physics update frame. They are not necessarily at the same frequency.

DC

Comment
Add comment · Show 2 · 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 davidcox70 · Jul 22, 2020 at 06:01 AM 0
Share

...actually if you must use velocity, just test commenting out your move() routine from FixedUpdate(). It could be that specifying an RB movePosition AND explicit velocity change overwrite each other. $$anonymous$$aybe.

avatar image TomatJuice davidcox70 · Jul 22, 2020 at 11:49 AM 0
Share

You were right the $$anonymous$$ovePositon was conflicting with the velocity

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

139 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

Related Questions

Horizontal/Parabolic Projectil Movement and Jump for 2D //HELP! 0 Answers

,Rotate a gameobject around another while being attracted by its gravity 1 Answer

2D rigidbody velocity relative to rotation? 0 Answers

how to jump at fixed height but faster 0 Answers

how to make an 2d object move the direction its facing using rigidbody2d.velcoity 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