Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AyJ_ · Mar 24, 2017 at 11:11 PM · unity 5rigidbody2dvelocitytransform.positionmoving

2D Endless game - Best method for moving objects?

I am developing 2D endless game, and I would like to know which method is the best for moving objects? Is it rigidbody2d.velocity or transform.position? I know that there is written that we should use rigidbody on all physics objects, yea, I know that, but I have rigidbody only on my main character, cuz only on this one I use gravity. Other enemies have colliders and I can move them by transform.position. I have tested both methods and think that my method for moving objects by transform.position is more smooth. So which one is better? My method or should I attach also rigidbody2d to other moving objects and use velocity for movement?

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
Best Answer

Answer by MelvMay · Mar 25, 2017 at 11:32 AM

http://lmgtfy.com/?q=unity+endless+runner :)

Comment
Add comment · Show 4 · 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 AyJ_ · Mar 25, 2017 at 11:52 AM 0
Share

O$$anonymous$$G, you think that I haven't done any research? Please read my question again. Thanks.

avatar image MelvMay ♦♦ AyJ_ · Mar 25, 2017 at 12:44 PM 0
Share

Well your question doesn't make sense to me.

I know that there is written that we should use rigidbody on all physics objects

Not adding a Rigidbody(2D) just means the collider gets implicitly and automatically added to a STATIC rigidbody behind the scenes called the ground-body. Static means you don't intend to move it so yes, if it's moving, add a Rigidbody. Rigidbody2D allows you to explicitly state the body type as well so if you're moving it then don't select a Static body type. Note that moving something under velocity means it moves through space. Setting the Transform position/rotation just means it instantly gets repositioned to the new pose without moving through the interviening space. The difference being that you don't get to use Rigidbody interpolation and that you're constantly forcing overlaps as you moving overlpped into other colliders. Using the velocity of a Rigidbody means you can use stuff like CCD which stops you tunelling through other colliders. You use the $$anonymous$$inematic body type if you want to expliclty control the movement of the body and you do not want it having any collision response. It also isn't affected by gravity but neither is a Dynamic body with its gravity scale set to zero. You use a Dynamic body if you want it to respond to collision forces. You talk about smooth and say moving via Transform.position is "smoother" but that must be subjective because it is in no way smoother than a body moving under its own velocity that uses linear interpolation per-frame. In the end, the choices of static, kinematic or dynamic are yours but the highlights are: static = you don't ever move it kinematic = you move it but try to move it by specifying body.position/body.rotation and not set the transform directly. The body colliders will not have any collision response. dynamic = you do not ever move it directly via transform or body.position/body.rotation but let it move via its own velocity. You can change the velocity directly or apply forces which do that indirectly. Gravity is also available here, scaled using the Rigidbody2D.gravityScale.
avatar image AyJ_ MelvMay ♦♦ · Mar 25, 2017 at 03:24 PM 0
Share

Thank you for your answer. I didn't know that if I create game object with collider and without rigidbody, that it automatically adds static rigidbody behind the scenes. So according to your explanation, if I have kinematic ridigbody, I should use rigidbody.$$anonymous$$ovePosition and if I have dynamic rigidbody, I should use rigidbody.velocity or rigidbody.AddForce, right? Also all these functions ($$anonymous$$ovePosition, velocity, AddForce) should be used in FixedUpdate and not in Update, yes? Could you also tell me when do you recommend to use Interpolation? I have found in doc, that it should be only used on my main character and not used on anything else, so should I stick to this rule?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can I move a Kinematic Rigidbody2d along the x-axis? 1 Answer

make a gameobject move to another gameobject that was selected by mouse click? 1 Answer

Unity Rigidbody2D bug 0 Answers

Instantiated Prefab no Rigidbody2D on Update function 1 Answer

Collision detection for the next frame 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