Having trouble with the physics here. I want the player(sphere game object) to be able to roll in every direction to navigate through the platform course. I can now go back and forth but trying to go to the side or diagnal isnt working properly here is the script. What am I doing wrong exactly?
UnityEngine;
using System.Collections;
public class SphereController : MonoBehaviour {
//The constant forward speed.
public float sphereSpeed;
//The user controlled left and right speed.
public float leftRightSpeed;
//Win or Loss.
public bool win;
public bool gameOver;
//The visual partical effect for when we collide.
//Just a cheap example.
public GameObject prefabVisual;
void Update ()
{
rigidbody.AddForce(Input.GetAxis("Horizontal"), 0, 0 * leftRightSpeed);
//transform.Rotate(new Vector3(0,Input.GetAxis("Horizontal"),0));
rigidbody.AddForce(0, 0, Input.GetAxis("Vertical") * sphereSpeed);
//Move forwards or backwards.
if (transform.position.z >= 19)
{
win = true;
//Disable movement of the sphere.
//Here we could load a different scene. Win screen, highscore screen, etc.
this.gameObject.GetComponent<SphereController>().enabled = false;
}
}
void OnCollisionEnter(Collision other)
{
//If we hit a obstacle.
if (other.gameObject.tag == ("Obstacle"))
{
//Tell us what we hit.
Debug.Log("Hit an obstical" + other.gameObject);
//gameOver = true;
//Instantiate the prefabVisual.
Instantiate(prefabVisual,transform.position,transform.rotation);
//Disable movement of the sphere.
this.gameObject.GetComponent<SphereController>().enabled = false;
//Make the sphere dissapear.
this.gameObject.GetComponent<MeshRenderer>().enabled = false;
//Could add a game over scene now.
}
}
}