Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by IsaiahKelly · Apr 13, 2018 at 02:16 AM · movementphysicstranslatekinematicworld coordinates

Using Rigidbody.MovePosition With Local Position and Lerp

I simply want to change this function to use Rigidbody.MovePosition instead of local transform position, but so far I can't figure out how to convert the local positions to something that works with that method. I've read the existing discussions on the topic, but none of them seem to apply to my particular situation. I know this must be pretty simple to do, right?

         // target here is a local offset position
         private IEnumerator MoveToPosition (Vector3 target)
         {
             float t = 0;
             Vector3 start = transform.localPosition;
 
             while (t <= 1)
             {
                 t += Time.fixedDeltaTime / m_Speed;
                 transform.localPosition = Vector3.Lerp (start, target, t);
                 yield return null;
             }
         }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by IsaiahKelly · Apr 16, 2018 at 12:10 AM

Okay, I was really overthinking this. I just needed to get (world) transform.position instead of transform.localPosition and feed that into the Rigidbody.MovePosition. Just make sure target value is also in world coordinates.

         private IEnumerator MoveToPosition (Vector3 target)
         {
             float t = 0;
             Vector3 start = transform.position;
 
             while (t <= 1)
             {
                 t += Time.fixedDeltaTime / m_Speed;
                 Rigidbody.MovePosition (Vector3.Lerp (start, target, t));
 
                 yield return null;
             }
         }


Comment
Add comment · 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
0

Answer by waikit97 · Apr 13, 2018 at 03:09 AM

 private float m_Speed = 10;
 public GameObject targetObj; //the target object
 public Rigidbody m_rb; //your moving object's RigidBody
 
     private IEnumerator MoveToPosition (GameObject target)
     {
         float t = 0;
         while (t <= 1)
         {
             t += Time.fixedDeltaTime / m_Speed;
             Vector3 start = transform.localPosition; //assign inside the while loop for updating your moving object's local position, since it moves
             m_rb.MovePosition(start + target.transform.localPosition * Time.deltaTime);
             yield return null;
         }
     }
Comment
Add comment · 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 IsaiahKelly · Apr 16, 2018 at 12:13 AM 0
Share

Thanks, but this doesn't seem to give me the desired effect and isn't using Vector3.Lerp It also didn't seem to work correctly when I tried it in my own code.

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

161 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

Related Questions

Simple Movement Game: Physics vs Manual Collision Detection? 2 Answers

Kinematics: Trying to get an object to land at a known point 1 Answer

Moving a kinematic object a fixed distance over a set time with physics in mind 2 Answers

Infinite Moving/Rotating Question 1 Answer

Which is better for player movement: physics or translation 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