So I have a cube, lets call it a dice (6 unique sides each with a different condition). The dice is viewed in isometric so 3 sides can be viewed at all times. this falls and can be rotated as it falls, think of it as a 3D city building tetris game. so with 3 sides view-able, there are 24 different ways it could land, and every single way needs to trigger a different set of actions (material change, which surfaces work for path-finding and adding/detracting scores).
So the rotation needs to be analysed at the moment it collides with the map. I have some script that rounds its rotation to the nearest 90 degrees, but the identifier statement I havenāt managed to figure out. I have tried the following:
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject)
{
var: Vector3 vec = transform.eulerAngles;
vec.x = Mathf.Round(vec.x / 90) * 90;
vec.y = Mathf.Round(vec.y / 90) * 90;
vec.z = Mathf.Round(vec.z / 90) * 90;
transform.eulerAngles = vec;
Debug.Log(transform.eulerAngles);
rigitbody.useGravity = false;
rigitbody.constraints = RigidbodyConstraints.FreezeAll;
if (transform.eulerAngles.x == 0 && transform.eulerAngles.y == 0 && transform.eulerAngles.z == 0)
{
Debug.Log("working");
rend.sharedMaterial = material[0];
transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue, Time.time * smooth);
}
}
}
and
if (transform.eulerAngles. == new Vector3(0,0,0)
{
Debug.Log("working");
}
and tried a few different combinations with collision in the if statements etc. Currently it reads with no errors but doesnāt actually actuate the scripts beneath it (Havenāt yet had the āworkingā statement pop up). So my first problem is this āif statementā line doesnāt recognize it. if I go back into unity the game object has the exact values that it should be reading.
My second issue is that my plan to address the 24 different conditions was to repeat this line 24 times with different parameters beneath each one (lots of else ifs) - Iām very new to coding and havenāt had much support in my learning but Iām sure thereās probably a much more efficient way to go about this. any ideas are appreciated. Sorry if this is an obvious fix but Iām under a tight deadline and everything I try doesnāt seam to work, and this game wonāt function without this bit working!
Cheers