• 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
1
Question by siddharth3322 · May 19, 2014 at 07:24 AM · rigidbody2dphysics2dunity4.3moveposition

rigidbody2D.MovePosition() Can't Found

As per my title suggest, I can't found rigidBody2D.MovePosition() method.

I have seen this method used in Catch Game.

Although I have downloaded latest Unity also. But I have same result. So what is the problem here? Please help me to solve this.

Comment
Add comment · Show 3
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 robertbu · May 19, 2014 at 03:36 PM 3
Share

Strange. I suspect he is using a beta of a future release. You can get approximately the same behavior by changing that line to:

 transform.position = targetPosition;
avatar image siddharth3322 · May 20, 2014 at 04:50 AM 0
Share

Thanks for information.

avatar image jrobertomar · Jul 21, 2014 at 12:37 AM 0
Share

transform.position = targetPosition;

Worked for me. Thanks!

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kiwasi · May 20, 2014 at 05:02 AM

There is no RigidBody2D.MovePosition() method. Link to docs

But it would be very useful to have a method like this that avoided the problems of Transform.Translate() when applied to a RigidBody.

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 siddharth3322 · May 20, 2014 at 05:04 AM 0
Share

I hope in future version we get this method available.

avatar image Kiwasi · May 21, 2014 at 12:46 AM 0
Share

To clarify, there is a RigidBody.$$anonymous$$ovePosition() method

There is not a RigidBody2D.$$anonymous$$ovePosition() method.

avatar image $$anonymous$$ · Nov 16, 2014 at 10:09 PM 0
Share

There is a Rigidbody2D.$$anonymous$$ovePosition() now http://docs.unity3d.com/ScriptReference/Rigidbody2D.$$anonymous$$ovePosition.html

avatar image siddharth3322 · Nov 17, 2014 at 03:27 AM 0
Share

Please add your comment as answer so that I can make it correct to help other members.

avatar image
0

Answer by bhison · Jun 26, 2015 at 03:05 PM

The advice on this thread is now out of date. MovePosition is a non-beta function in the standard release. (documentation)

Using this function is different to how it is explained in the video; just following instructions will lead to compiler errors. Following the guidance in documentation I have made the following code which operates as expected:

 using UnityEngine;
 using System.Collections;
 
 public class HatController : MonoBehaviour {
 
     public Camera cam;
 
     // Use this for initialization
     void Start () {
         if (cam == null) {
             cam = Camera.main;
         }
     }
     
     // Update is called once per physics timestep
     void FixedUpdate () {
         Vector3 rawPosition = cam.ScreenToWorldPoint (Input.mousePosition);
         Vector3 targetPosition = new Vector3 (rawPosition.x, 0.0f, 0.0f);
         GetComponent<Rigidbody2D>().MovePosition(targetPosition);
     }
 }

As you may see - the only thing I have done differently is used GetComponent to get a reference to the object's rigidbody, rather than just stating "RigibBody2D" as a reference itself. I hope this helps someone!

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 tanoshimi · Jun 26, 2015 at 03:07 PM 1
Share

Calling GetComponent in FixedUpdate() is pretty bad advice. Call it in Start(), store it in a local variable, and use that in FixedUpdate ins$$anonymous$$d.

 private Rigidbody2D rb2D;

 void Start(){
   ...
   rb2D = GetComponent<Rigidbody2D>();
   ...
 }

 void FixedUpdate() {
     ...
     rb2D.$$anonymous$$ovePosition(targetPosition);
     ...
 }


avatar image bhison · Jun 26, 2015 at 03:15 PM 0
Share

That's actually what I had done originally but thought it was an unnecessary convolution. Is it just best practice on the basis that you could have reason to call the rigidbody again later? Or something else? Thanks!

Edit: Oh, wait, I see. It's creating extra work in the update cycle.

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

25 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

Related Questions

How to create an Asteroids style moving in 2D mode? 2 Answers

Rigidbody2d.MovePosition on Update vs FixedUpdate 1 Answer

Am I using MoveTowards and MovePosition wrong? 1 Answer

Unity2d Set Different Physics Properties on Gameobjects (potentially at Runtime) 2 Answers

How to make physics relative to moving parent 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