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 Khena_B · Feb 03, 2017 at 08:55 PM · 2dphysicscollidermaterialruntime

Changing physical material impossible?

Hey,

Trying to change the friction on a physical material 2D at runtime

 capsule.sharedMaterial.friction = 0;

Does not work, if i inspect the physical material it will say 0 but it isn't actually 0, it's still acting like 1.

The only way to make it work is by disabling and re-enabling the collider

 capsule.sharedMaterial.friction = 0;
 capsule.enabled = false;
 capsule.enabled = true;

This causes a ton of issues, from triggers triggering constantly or not functioning to my character being stuck in walls, there has to be a proper way to do this??

Comment
Add comment · Show 6
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 Khena_B · Feb 03, 2017 at 09:23 PM 0
Share

I see this has been a problem since 2013 and possibly even earlier, is nothing being done about this, what is going on?

avatar image Scoutas · Feb 03, 2017 at 10:33 PM 0
Share

I would say keep a reference to the material itself somewhere and change the value in the material, and not the one applied on the Collider itself (I take it capsule is of type Collider), and then reapply that material on top.

avatar image Khena_B · Feb 03, 2017 at 10:42 PM 0
Share

Not sure i understand Scoutas but i've made a public Physical$$anonymous$$aterial2D variable and assigned my mat to it, then i do:

 phys$$anonymous$$at2D.friction = 0;
 capsule.shared$$anonymous$$aterial = phys$$anonymous$$at2D;

It doesn't make a difference, i've even tried to set the capsule's material to null then re-assigning phys$$anonymous$$at2D and no difference!

avatar image Scoutas · Feb 03, 2017 at 11:03 PM 0
Share

Another question then. Did some poking around, found someone saying that the collider can't be a trigger. Try creating a new cube, add just a collider to it and try updating the Physics$$anonymous$$aterial2D then. If it works, then your setup of the capsule/player has a mistake somewhere

avatar image Khena_B Scoutas · Feb 03, 2017 at 11:19 PM 0
Share

Unfortunately my collider isn't a trigger, ive tried it in an empty project as well and the same happens, i'm surprised that this has never been solved, either i'm doing something wrong or nobody has ever changed their physical material 2D at runtime.

avatar image Khena_B · Feb 03, 2017 at 11:57 PM 0
Share

Ive tried assigning and changing the physical material on the Rigidbody2D ins$$anonymous$$d, same problem, the Collider has to be disabled then re-enabled.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Feb 03, 2017 at 10:10 PM

I don't see a "friction" variable in the Script Reference. Sure you aren't using a deprecated variable?

Comment
Add comment · Show 2 · 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 Khena_B · Feb 03, 2017 at 10:13 PM 0
Share

https://docs.unity3d.com/560/Documentation/ScriptReference/Physics$$anonymous$$aterial2D.html

avatar image FortisVenaliter Khena_B · Feb 06, 2017 at 05:14 PM 1
Share

Ah, my apologies. Was looking at 3D ins$$anonymous$$d of 2D.

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

142 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 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

Combining multiple box colliders into one edge collider 0 Answers

what value should i change to get football from material 1 Answer

How to animate collider along with object for 2D game? 0 Answers

Create new Physics material via C# script 1 Answer

Sprite does not rotate with a CircleCollider2D 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