Hi, im working in a project to make some stuff for a maze game.
I have this cylinder primitive object with a sphere or capsule collider and a rigidbody attached. Also a script with speed settings. In this script it also says that if it detects collisions with certain objects, it will revert speed.
Even though it has a speed value set and a rigibody with gravity, it does not roll.
It should be rolling at a constant force forward and backwards if it collides.
What can i do?
A video upload to get the picture
using UnityEngine;
using System.Collections;
public class SpikeWheelBehaviour : MonoBehaviour {
public float speed;
public GUIText displayText;
public bool changeDirection;
// Use this for initialization
void Start () {
changeDirection = false;
displayText.text = " ";
}
void OnCollisionEnter(Collision other){
if (other.gameObject.name == "OWwest01" ||
other.gameObject.name == "OWsouth01" ||
other.gameObject.name == "SpikeWheelX" ||
other.gameObject.name == "SpikeWheelZ" )
{
displayText.text = " Collided with an object ";
changeDirection = false;
moveForward();
}
else {
displayText.text = " No Collision ";
}
if (other.gameObject.name == "OtherWall01" ||
other.gameObject.name == "OWnorth01" ||
other.gameObject.name == "SpikeWheelX" ||
other.gameObject.name == "SpikeWheelZ" )
{
changeDirection = true;
moveForward ();
displayText.text = " Collided with an object ";
}
else {
displayText.text = " No Collision ";
}
}
// Update is called once per frame
void Update () {
moveForward ();
}
void moveForward(){
if (!changeDirection)
{
transform.Translate (Vector3.forward * speed * Time.deltaTime);
//changeDirection = true;
}
else
{
transform.Translate (-Vector3.forward * speed * Time.deltaTime);
//changeDirection = false;
}
}
}