- Home /
detection cube face while rotating
Hi, I have made this script to detect the face I am touching, on a cube, with a 3d ball. so I attached this rigidbody on this ball and touched different face on a cube, all is working good, if the cube rotation is set to 0, 90 ,180 and 360, so if it's parallel... it's working. but while the cube is rotating, nothing work anymore.
the script:
public class hittingobj : MonoBehaviour
{
public Transform ball;
public string oggetto;
public bool Top;
public bool Bottom;
public bool Forward;
public bool Back;
public bool Left;
public bool Right;
public Vector3 MyNormal;
public bool attiva_Left;
public bool attiva_Right;
public bool attiva_Top;
public bool attiva_Bottom;
void OnCollisionEnter(Collision other)
{
if(transform.name == oggetto){
MyNormal =other.GetContact(0).normal;
if(attiva_Right){
if( MyNormal == ball.transform.right ){
Right=true;
}
}
if(attiva_Left){
if( MyNormal == -ball.transform.right ){
Left=true;
}
}
if(attiva_Top){
if( MyNormal == ball.transform.up ){
Top=true;
}
}
if(attiva_Bottom){
if( MyNormal == -ball.transform.up ){
Bottom=true;
}
}
}
}
}
I understand the problem is in the if statement, I don't know how to compare the normal when the cube is rotating, someone ha a solution?
Comment
Your answer
Follow this Question
Related Questions
Detect polygon? 0 Answers
How to check if two objects collide without a collider 1 Answer
Best way to implement splash colliders? 0 Answers
How can i get harmed and healed by diferent game objects 0 Answers