- Home /
how detect the angle of collision on disc object ?
so i have a disc , that has 3 parts or areas , and three spheres that collide with it , so i want a script that makes the disc detect which angle or area the sphere hit the disc , if the sphere hit the wrong area its game over , if it collides with the matching area the game keeps going , i truly need this , i searched everywhere and couldn't put it to work , thank you !
Answer by Cornelis-de-Jager · Jul 25, 2019 at 09:15 PM
So instead of trying to detect where on the circle it hits (and it is possible), an easier way would to be have a parent object with no collier. Then have 3 children with colliders. the Parent will have the following script:
public class CheckCollision : MonoBehaviour {
ActionController ac;
bool safeToHit;
public void SetSafe() => safeToHit = true;
public void SetNotSage() = safeToHit = false;
void OnCollisionEnter (Collider other) => ac.ProcessHit (safeToHit);
void Start () => ac = transform.parent.GetComponent<ActionController> ();
}
Then the Parent will have the scirpt ActionController
and will look as follow:
public class ActionController : MonoBehaviour {
public void ProcessHit (bool safeToHit){
if (!safeToHit){
// The player hit the wrong area
}
}
}
This way you don't have to worry about mathematics, and if the rotation of the object should change or you need to add more sides, this method is very adaptable.