Trying to make my first bowling game with Unity, I ran into the problem of knowing when a pin is down.
Right now, I check it’s up-vector y to see if it’s less than sin(45°). Most of the time it works but not always.
Maybe there is the need to check other vectors values but can’t figure it out which one.
Here is my current script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BirillCounter : MonoBehaviour
{
[SerializeField]
private static Text textCounter;
private static int index = 0;
private static int counter = 0;
private static GameObject[] birills = new GameObject[7];
void Start()
{
if (textCounter == null)
{
textCounter = GameObject.Find("Counter").GetComponent<Text>();
}
birills[index++] = this.gameObject;
}
void OnCollisionEnter(Collision collision)
{
print("Collision");
if (!this.gameObject.tag.Equals("DOWN"))
{
float sin45 = Mathf.Sin(45 * Mathf.Deg2Rad);
if (this.transform.up.y < sin45)
{
this.gameObject.tag = "DOWN";
print("Down");
textCounter.text = ++counter + "";
}
}
}
}