Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ItzMrJohn2You · May 23, 2015 at 10:54 PM · physicsrigidbodybounce2d physics

Changing physics properties of a gameobject through code.

I have a sphere in this little game i'm building, and sometimes its a bouncy ball and sometimes its a metal ball. The bouncy ball works perfect but when I change to metal ball and ball is in the air it bounces too. I have the physics materials set. I also put a physics material on platform that has no bouciness. The only thing that works is a surface effector that doesn't use bounce. I dont want to change the bool on all surface effectors and I don't want surface effectors on everything. Here is a piece of my code, I change properties with a button.

P.S. This is a 2D game.

 public void HeavyBall()
 {
     surEffect.useBounce = false;
     rend.sharedMaterial = solid;
     col.sharedMaterial = heavyBall;
     rigidBody.gravityScale = 3f;
     rigidBody.drag = 0.2f;
     rigidBody.angularDrag = 0.5f;
 }

 public void RubberMaterial()
 {
     surEffect.useBounce = true;
     rend.sharedMaterial = rubber;
     col.sharedMaterial = bouncingRubber;
     rigidBody.gravityScale = 1f;
     rigidBody.drag = 0f;
     rigidBody.angularDrag = 0.05f;
     if(isOnGround)
     {
         rigidBody.velocity = new Vector2( 0f, 7.5f);
     }
 }
Comment
Add comment · Show 2
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 UnityCoach · Dec 03, 2015 at 12:32 PM 0
Share

Hi,

I'm having the same issue in my current project. I'm not 100% sure, but it seems to me that bounciness and friction values are somehow swapped. It's when I bring friction to 0 that the rigid body stops bouncing.

Did you end up finding a solution to this?

avatar image meat5000 ♦ UnityCoach · Dec 03, 2015 at 01:58 PM 0
Share

LOL if this is the case it'll be the find of the century :P I've been plagued by see$$anonymous$$gly random bounciness for ages

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · Dec 03, 2015 at 02:16 PM

Hi there

I could be wrong but I believe you should be changing the material of your collider, not the sharedMaterial. sharedMaterial is the base material that your collider's material is created from - it's a bit like the prefab for its physics material. The material that it is actually using is collider.material.

See definitions of material and sharedMaterial for collider:

http://docs.unity3d.com/ScriptReference/Collider.html

Also not sure what this bit does:

  if(isOnGround)
      {
          rigidBody.velocity = new Vector2( 0f, 7.5f);
      }

That strikes me as a curious bit of code - probably not the problem, but still odd!

-Chris

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

22 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

Related Questions

RIGIDBODY HOW MAKE IT STOP BOUNCING HELP! 3 Answers

How could I make a bouncy object move mostly along the Z axis? 1 Answer

Re-Creating Unity's Friction and Bounce 0 Answers

Click to Move RigidBody Bouncing 2 Answers

Avoid bouncing when ground move down 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