Hey everyone, i’m making a roll a ball game and i followed the unity tutorial on making it. I’m fairly new to coding so this is getting a little complicated for me. There’s probably allready an answer but i can’t figure out how to implement that into my code…
I’ve also followed a third person camera tutorial so i can orbit the ball im controlling, but the movement is off course not following the direction the camera is facing. if anyone has an idea how to get the ball to roll into the direction the camera is facing that would be great
here’s the playercontroller code:
public class Playercontroller : MonoBehaviour {
public Text winText;
public Text countText;
public float speed;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody> ();
count = 0;
countText.text = "Score: " + count.ToString ();
winText.text = "";
}
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")) {
StartCoroutine (destroyOther (other));
}
}
IEnumerator destroyOther(Collider other)
{
Material mat = other.GetComponent<Renderer> ().material;
Color matC = mat.color;
float t = 0f;
while(t < 1f){
t += Time.deltaTime / 0.2f;
yield return 0;
float a = Mathf.Lerp (1f,0f, t );
matC.a = a;
mat.color = matC;
}
other.gameObject.SetActive (false);
count = count + 1;
countText.text = "Score: " + count.ToString ();
if (count >= 13)
{
winText.text = "You Win!";
}
}
}