• 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
Question by Geekguy100 · Aug 27, 2018 at 04:17 AM · 2drigidbody2dgravityplatformermoveposition

Rigidbody2D falls slowly with MovePosition?

I'm trying to make a simple 2D character controller, but with the following code the player falls extremely slowly! I've seen similar problems before, but I can't seem to find a working answer. I know I could directly set rb.velocity, but I'm curious as to why t$$anonymous$$s is not working. Any thoughts? Thanks! using UnityEngine;

 public class PlayerMotor : MonoBehaviour {
 
     private Rigidbody2D rb;
     private Vector2 vel;
     private bool jumped;
 
     private void Awake()
     {
         rb = GetComponent<Rigidbody2D>();
     }
 
     public void Move(float h)
     {
         vel = new Vector2(h, rb.velocity.y);
         //transform.Translate(vel * Time.deltaTime);
     }
 
     public void Jump()
     {
         jumped = true;
     }
 
     private void FixedUpdate()
     {
         rb.MovePosition(rb.position + vel * Time.fixedDeltaTime);
     }
 }
 
Comment

People who like this

0 Show 8
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 NoDumbQuestion · Aug 27, 2018 at 04:40 AM 0
Share
 rb.position + vel * Time.fixedDeltaTime

You should use transform to set position. Use rigidbody to set position does nothing but break engine if you dont know what you are doing.

avatar image Geekguy100 NoDumbQuestion · Aug 27, 2018 at 04:19 PM 0
Share

Ok. Just a few questions: 1.`transform.position = rb.position + vel * Time.fixedDeltaTime` goes into FixedUpdate() correct? 2. Why use rb.position and not transform.position? for example: transform.position = transform.position + vel * Time.fixedDeltaTime' and put that into Update() over FixedUpdate()? I just wanna try to understand things and not copy it verbatim. Thanks again!

avatar image NoDumbQuestion Geekguy100 · Aug 27, 2018 at 04:35 PM 0
Share

Anything related to Physics must be in fixedUpdate(). You was doing it right.

Here is different between using transform and rigidbody for movement

Transform set position give you flexibility of controlling speed and direction based on input like most of arcade, platform game.

Rigidbody is for more real feeling movement of human like that can be slow, accelerate as needed (most use for console game + fews 2D game need dynamic Physics) which need some more extra work.

You can only pick one way to control movement as one will break another. In most case, people go with transform set position since it is much simpler and no one notice the difference

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by vitaly · Aug 28, 2018 at 03:32 AM

Is your rigidbody kinematic or not?

Comment

People who like this

0 Show 1 · 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 Geekguy100 · Aug 28, 2018 at 04:05 AM 0
Share

Nope. It's dynamic

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

248 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to fix Rigidbody2D working slower on lag 0 Answers

2D Physics movement system is creating unexplained random variations. 0 Answers

Changing gravity depending on character/camera rotation 0 Answers

Unity 2d random Enemy and random direction movement on spawn. 0 Answers

My Unity Rigidbody 2D character fall slowly after a jump,Unity RigidBody Character falls slowly 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