Okay, so, currently within my game I have got 5 or 6 "police cubes" that chase after the player, and deduct health until eventually the player is dead. My player also has to pick up collectables in order to get to the finish line. My player is a rolling ball, and there is a main road for the ball to travel on. This road has a surrounding dirt environment, and I need a way for the speed to be deducted once the rolling ball comes into contact with it. If anyone could help me with this it would be greatly appreciated, thank you.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class _PlayerController : MonoBehaviour {
public float speed = 75.0f;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 25) {
Application.LoadLevel (2);
}
}
}
You could apply a Physic Material to the dirt and give it a Dynamic Friction value. The value you give it will depend on how much you want the dirt to slow the player down, try 0.5 as a starting point.
To create a Physic Material select Assets > Create > Physic Material from the menu bar. Then drag the Physic Material from the Project View onto a Collider in the scene. (Copy pasted from the linked page).