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 /
avatar image
0
Question by RealMTG · Jan 03, 2016 at 05:00 PM · rigidbodymoveposition

How can I move a rigidbody to a desired position with interpolation?

Hi

I have a rigidbody player I want to move to a desired position. I don't want it to move it like you would normally have a player move. I just want to move it from Point A to Point B with interpolation, like using Vector3.Lerp. The reason I want to use the rigidbody instead of V3.Lerp is because the lerping slows down the closer it gets to the target and that messes with my code and the feel of of the player.

So this is the two ways I've tried doing this.

 void FixedUpdate()
 {
     rig.MovePosition(movePosition * Time.deltaTime * moveSpeed);
 }

The problem with this is that the player just gets stuck at around 0,0,0 and can not be moved. I have no idea what is going on when this happens.

Then I tried this.

 void FixedUpdate()
 {
     rig.MovePosition(tr.position + movePosition * Time.deltaTime * moveSpeed);
 }

The problem with this is that the player keeps walking endlessly since it is always adding the movePosition and transform position.

I have no idea what I am supposed to now.

Any help with this is greatly appreciated!

Comment
Add comment · Show 1
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 NoseKills · Jan 04, 2016 at 05:18 PM 0
Share

The reason I want to use the rigidbody ins$$anonymous$$d of V3.Lerp is because the lerping slows down the closer it gets to the target

No it doesn't. Vector3.Lerp just calculates a vector based on the parameters you give. The results it gives depend only on the parameters you put in. $$anonymous$$ost likely you are doing something like

 transform.position = Vector3.Lerp(transform.position, x, Time.deltaTime)

It causes slowing down because if deltatime is let's say 0.05, the object moves 5% of the RE$$anonymous$$AINING distance every frame and the remaining distance gets smaller all the time.

2 Replies

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

Answer by Munchy2007 · Jan 03, 2016 at 06:02 PM

Use Vector3.MoveTowards() this will result in a constant speed movement from the start position to the target position.

http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html (substitute rigidbody.movePosition for transform.position in the script reference example).

You can compare your rigidbody.position with target position and when they are close enough you can stop moving.

Edit: Vector3.Lerp() can produce the same result as movetowards if it's used properly, i.e. not with Time.deltaTime as the 3rd parameter.

Comment
Add comment · Show 3 · 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 RealMTG · Jan 03, 2016 at 06:23 PM 0
Share

I ended up using Vector3.$$anonymous$$oveTowards. Thanks for the help!

avatar image Munchy2007 RealMTG · Jan 03, 2016 at 06:42 PM 0
Share

You're welcome, glad it helped :)

avatar image ieselisra · Mar 12, 2017 at 01:39 AM 0
Share

Works better as $$anonymous$$ovePosition, but it rotates on target to original rotation.

Do you know how to fix it?? Thanks

avatar image
0

Answer by MrFloxy · Jun 27, 2021 at 10:44 AM

unfortunately, your transformation method is not correct, since objects move in jerks, I would like to get a smooth movement of objects using physics

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

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

39 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

Related Questions

Rigidbody.MovePosition/MoveRotation Hits far away colliders 2 Answers

How to move player according to where camera is facing. 0 Answers

Rigidbody MovePosition clipping 1 Answer

Some objects working fine at 50 fps, while other objects lagging? 3 Answers

rigidbody.moveposition local coordinates? 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