Changing Player Friction

Here’s a super simple question:

So all I’m doing is trying to decrease the player’s friction (with a C# script), but I’ve been wandering around searching for a solution to something this stupidly simple for over 2 hours!!!

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    void Awake() {
        collider.material.dynamicFriction = 0;
        collider.material.staticFriction = 0;
    }
}

This is as close as I have come to any real solution, but to be honest I have no idea what to do with this code. In the example in Unity’s documentation they have the code just like this, but when I attach it to the player it doesn’t work.

What am I missing here?
Thanks!

In order for the code above to work, the player’s collider needs to have a physics material.

http://unity3d.com/support/documentation/Manual/Physics.html

Assuming you already assigned one to the player’s collider, run the game with the code you posted above, and check the physics material’s values. If their value is 0, the code is doing its job. If not, then make sure your script is attached on the same object as the collider component, and not one of its children.

That went a little over my head. So I assign a physics material to the player’s collider? How do I access the player’s collider, and which physic’s material should I use? I added a ridged body component to the player, but that didn’t do anything.

You say you have no idea how to use this code so let me go very basic.

make a new file name it: PlayerMovement.cs
Now drag and drop it onto the object that has the collider (in the components on the right) like Diviner said.

That should work.

God I’m hopeless. That didn’t work for me at all. I did what you said and nothing happened. Is there is a special kind of collider I need to use?

You need to assign a physics material to the object’s collider. Not via script, through the Editor. Check the link in my previous post, then scroll down to where it says physics material. It has a step by step explanation on how to do so. Quoting the actual article :

Ah-ha! So I was just working on getting a cube to slide around first, and I got it to work by adding a rigid body to it and applying the physics material to it’s collider. However, this still didn’t work until I attached the physics material to the floor as well (something you didn’t mention so I wonder if this method is correct).

Then I tried to apply this method to the player, and I followed the same steps I did with the cube. However, the FPS controller’s character controller component can not have physics materials added to it, so no dice. Instead I added my own box collider to the player, as well as a rigid body like I did with the box I tested this setup on, but still it didn’t work. Finally, I removed the FPSInput Controller (script), Character Motor (script), and Character Controller (Script), because it will not let me remove the Character Controller without removing these other components. After that I set my character up on a hill and it worked!

So this is great and all but now I can only look around with my character, I can’t move anymore because I removed these scripts. Does this mean that I should rewrite the FPS controls using the rigid body and box collider instead of using a character controller? That seems like a lot of unnecessary work, but this is also the only way I can see to get this to work.

Thanks for all the help!

Well, you’re trying to emulate physics movement with a non physics controller. Of course you’re going to run into such issues.

My take on this, if you want physics like friction, and you can’t be bothered making your own custom ones, use a physics material and convert your control script from CharacterController to Physics. There are plenty of physics controllers on the wiki, you can use one as-is from there. Here’s a few :

http://www.unifycommunity.com/wiki/index.php?title=PhysicsFPSWalker

http://www.unifycommunity.com/wiki/index.php?title=VariableSpeedFPSwalker

Since you seem pretty new at this, I figure it can’t hurt for a little overview. I’ve just gone through this whole process myself, and here’s basically my conclusion.

For moving around a First-Person Controller, you have basically two options. You can use the Unity default, which feels nice and means you don’t have a lot of work that you have to do yourself, but it’s not that customizable. I can’t remember if the default has a rigidbody or not, but you can also adjust the drag and mass of an object to change the feeling of movement within the rigidbody component.

The other option is to write all the movement stuff yourself, either by repositioning using the transform or by using Physics to apply forces to the rigidbody. This option is a lot more customizable and realistic, but it means that you basically have to write all your own movement and input scripts. (Which, admittedly, is not as intimidating as it sounds.) So it’s up to you what you feel is best for your project.

I know that’s not a very specific answer, but it’s the sort of thing that would have really helped me a month or two ago when I was starting out. Hope it helps you!

Haha, yeah Diviner I eventually stumbled upon those links and used the RigidbodyFPSWalker as a template for my custom setup.

Also, thanks Kagedtiger for the advice, I’m still not sure if my current script has the effect I truly want, but at least I have gotten a start after 4+ hours of being completely stuck. I can only hope that things will get easier as they go along.

You can consider this case solved, a big thanks to everyone that helped!
~TacoShank

I change de slope limit of character controller to 90 . Solved to me.

Both changing the slope limit of the character controller and adding physics material with friction values set to 0 didn’t work
for me. Are there any other solutions