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 Jakeiiii · Sep 09, 2015 at 09:54 AM · movementrigidbodypositionsmoothtranslate

Move a Rigidbody by a specific certain amount in a smooth motion?

So I'm basically trying to get my character to push a block (rigidbody), however when I set it to go at a velocity and have it stop after a certain amount of time (via the WaitForSeconds() function), it doesn't move the same amount each time. Using Vector3.Lerp with its position and smoothing it with Time.deltaTime also gives the same problem (not to mention, it has the block moving through other collisions when done this way).

Basically think of block-pushing in Zelda. How do I get it to move the same amount each time and move so smoothly too?

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

Answer by Jakeiiii · Sep 10, 2015 at 04:10 PM

Okay so I've managed to get a solution. Basically, I get the position that the box started in (origin) and then the point I want it to go to (origin+distance). I make the box move at a fixed velocity, with no drag/friction whatsoever. When the box moves, it isn't kinematic, and when it's stationary, it is kinematic. I then check the distance that it has traveled from the origin and the distance between the box and its destination. I make two boundaries out of the two distances and when it is a small distance from the origin or has gone too far past it, then it will stop moving and be positioned at the destination. I've also used Raycasts to check if the box won't be able to make the entire journey, so if not then it cannot be pushed/pulled. There are other complexities that I have omitted for the sake of only saying the important parts but that is the general idea.

Thanks to Peaj for your ideas. :) @Peaj

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
2

Answer by Peaj · Sep 09, 2015 at 12:57 PM

You could use Rigidbody.MovePosition together with Vector3.MoveTowards. MoveTowards does the same thing as lerp except it wont overshoot your target. Rigidbody.MovePosition will make sure that your block collides on its way.

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 Jakeiiii · Sep 09, 2015 at 02:28 PM 0
Share

I assume you mean to use RB.$$anonymous$$ovePosition(Vector3.$$anonymous$$oveTowards(xxx))? This still has the box going through things unfortunately, but at least it's moving at specifics amounts.

avatar image Peaj · Sep 09, 2015 at 04:27 PM 0
Share

Yeah thats right. I guess you would have to use OnCollisionEnter to check wether a collision is happening. If it coullides you have to stop moving it. The collision detection should work just fine like that but if you go on moving the object by script it can't react in a proper physical way.

avatar image Jakeiiii Peaj · Sep 10, 2015 at 02:09 PM 0
Share

But then it won't react until the box has gone through something. It's ridiculous how this is something that is actually difficult to do; isn't there any kind of rigidbody movement function that goes between two Vector3s and has adjustable speed? :P

avatar image Peaj · Sep 10, 2015 at 03:59 PM 0
Share

If you use OnCillisionEnter it will react exactly the moment it collides with the object. The same moment the physic engine would react to the object. It does not go all the way into the object.

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

28 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

Related Questions

Jump is higher then normal 0 Answers

Move NPC on triggerEnter 0 Answers

Player Rotation and movement 0 Answers

Stop moving gameObject and push it back 0 Answers

Change direction of rigidbody when force is no longer being applied 2 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