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 Viandox_ · May 11, 2020 at 01:57 PM · rigidbody2denergyrebound

Rebound losing energy

Hi, I've been trying to fix my problem for quite some time and I still can't so I hope someone here will be able to. I've go a falling Rigidbody2D (without velocity at start), with y positive :

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

When reaching y = 0, I want it to "rebound" (in thin air), for that, I only invert the velocity.y :

     private void Update()
     {
         if (rigidbody2d.position.y < 0f && rigidbody2d.velocity.y < 0f)
         {
             rigidbody2d.velocity = -Vector2.up*rigidbody2d.velocity.y;
         }
     }

My object shouldn't lose energy at all because I've set all drags to 0. However, rebound after rebound, the objet goes less and less high. I'd like it to be able to bounce at the same high every time. Obviously, FixedUpdate gives the same result.

If anyone knows what's causing that effect and correct it, please tell me! Thanks in advance

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
0

Answer by Eudaimonium · May 11, 2020 at 02:02 PM

Hmm. Replace the velocity invert with:

         Vector3 velocity = rigidbody.velocity;
         velocity.y *= -1;
         rigidbody.velocity = velocity;

What you're doing is only setting a velocity to the new Vector that will have the magnitude equal to previous velocity Y component, instead of being equal to previous velocity magnitude. If the velocity was not perfectly vertical, it will be less after your invert because you discarded X and Z components.

Disclaimer, I have not tested this. Lemme know if it works.

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 Viandox_ · May 11, 2020 at 04:37 PM 0
Share

Thanks for your answer! I've tested, it gives the same result I had, each rebound getting lower. In my case, only the Y velocity isn't void as the movement is only afected by gravity and starts still

avatar image Eudaimonium Viandox_ · May 11, 2020 at 04:49 PM 0
Share

What exactly is the desired behavior you wish to achieve? Perhaps using physics engine for something like that is a wrong approach. Perhaps try looking into Animator, animation clips, or AnimationCurve class to achieve the desired bouncing effect (of course, if the thing bouncing isn't supposed to react to physics)?

avatar image Viandox_ Eudaimonium · May 11, 2020 at 05:29 PM 0
Share

The goal is something more complicated than that, but that example is the easiest one which revealed my problem. In terms of energy, the kinetic energy is void at the beginning, while the gravitational potential energy is at his maximum. When falling, the gravitational potential energy decreases, but the kinetic one rises (total energy remains constant). That way, when I the Y velocity is inverted, the kinetic energy should be able to get the object back to its initial position. $$anonymous$$y problem is that isn't the case and I can't understand why and I need to

Show more comments

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

129 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

Related Questions

2D Bounce gains energy each time 1 Answer

My flipped character ragdoll has wrong hingejoint anchor positions 0 Answers

Rigidbody2D.IsKinematic giving object reference not set? 0 Answers

Drag to add power, release to throw at opposite angle (RigidBody2D), strange beahviour. 3 Answers

2DColliders going through eachother 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