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
11
Question by Oudaiesty · Mar 10, 2010 at 11:08 PM · velocity

How do I zero out the velocity of an object?

The problem i'm having this time is that when I hit a group of objects and then reset their positions I can't Zero out their velocity so its like they are constantly being hit.

How can I zero out their velocity?

I have a script that was provided by -Duck but it needs something to fix that last issue.

Heres what he showed me:

var originalPosition : Vector3; var originalRotation : Quaternion;

@script AddComponentMenu("Misc/Location Reset") function Awake() { originalPosition = transform.position; originalRotation = transform.rotation; }

function ResetPosition() {

 transform.position = originalPosition;
 transform.rotation = originalRotation;


}

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

Answer by Lipis · Mar 11, 2010 at 01:49 AM

You can do that by setting the velocity and angularVelocity of the Rigidbody to zero:

rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;

And just to make absloutely sure that it won't move a centimeter you might want to call Sleep() afterwards:

rigidbody.Sleep();

But according to Unity:

In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don't set the velocity of an object every physics step, this will lead to unrealistic physics simulation.

Comment
Add comment · Show 5 · 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 duck ♦♦ · Mar 11, 2010 at 10:18 AM 1
Share

Remember to zero out the angularVelocity too!

avatar image Lipis · Mar 11, 2010 at 11:40 AM 0
Share

Thank you @Duck! I edit the answer..

avatar image AngryAnt ♦♦ · Mar 11, 2010 at 02:11 PM 1
Share

The quote is right. A physical object would usually not stop dead suddenly, but that is all that is meant with that quote. Just to make absolutely sure you're not gonna move one inch further, you might want to rigidbody.Sleep (); right after zeroing the velocity. Ah and no reason to do transform.rigidbody. $$anonymous$$onoBehaviours also have a rigidbody accessor - edited your answer to reflect it.

avatar image Lipis · Mar 11, 2010 at 02:51 PM 0
Share

@AngryAnt thanks.. I also added the Sleep() in the answer and hopefully you don't $$anonymous$$d that I changed the inch to centimeters... :)

avatar image parth16parikh · Jan 10, 2018 at 10:29 AM 0
Share

Helped me! Thanks @Lipis and @AngryAnt ! I was setting velocity and angular Velocity to 0 but it still didn't stop the body. Adding the sleep call made it to work! Thanks :)

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

2 People are following this question.

avatar image avatar image

Related Questions

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Removing velocity relative to the contact normal 1 Answer

Mass affecting velocity 2 Answers

Target Range Situation 1 Answer

Local Velocity 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