The material is applied but the ground is not slippery. Why? (The friction is at 0)
I believe the material needs to be applied to a Rigidbody component, rather than a Collider component.
Correct me if I’m wrong.
That is incorrect, the PhysicsMaterial2D on the Collider2D will override the PhysicsMaterial2D on the Rigidbody2D. From the docs;
How are you moving your cube in this scene? Is your cube’s Rigidbody2D kinematic?
Good to know, thanks.
First I tried to use Physics Material change Dynamic and static Friction to zero. But then I realize that’s not the solution what you want.
private void Update()
{
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveH, 0.0f, moveV);
GetComponent<Rigidbody>().AddForce(movement * 0.005f * Time.deltaTime);
}
But I also found one reference online you can think about it because my codes do not consider the Layer.
using UnityEngine;
using System.Collections;
public class PlayerController2 : MonoBehaviour {
public float speed;
public float torque;
void FixedUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce (movement * speed * Time.deltaTime);
GetComponent<Rigidbody>().AddTorque (Vector3.up * torque * moveHorizontal);
GetComponent<Rigidbody>().AddTorque (Vector3.up * torque * moveVertical);
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "IceFloor") {
GetComponent<Collider>().material.dynamicFriction = 0;
}
}
void OnTriggerExit(Collider other){
if (other.gameObject.tag == "IceFloor") {
GetComponent<Collider>().material.dynamicFriction = 1;
}
}
}
Here is the reference: How to create icy floor? c# - Questions & Answers - Unity Discussions