public void DoRoll(Vector3 dir) { if (m_CanRoll) { ResetPosition(); Vector3 ndir = Vector3.zero; if (Mathf.Abs(dir.x) == 1) { ndir = dir * m_Cube.bounds.size.x / 2f; } else if (Mathf.Abs(dir.z) == 1) { ndir = dir * m_Cube.bounds.size.z / 2f; } Vector3 newAxis = m_Cube.ClosestPointOnBounds(m_Cube.transform.position + ndir); newAxis.y = m_Cube.bounds.min.y; Vector3 thisPos = new Vector3(); thisPos = m_Cube.transform.position; Quaternion thisRot = new Quaternion(); thisRot = m_Cube.transform.rotation; transform.position = newAxis; transform.rotation = Quaternion.identity; m_Cube.transform.rotation = thisRot; m_Cube.transform.position = thisPos; Vector3 targetRotation = new Vector3(dir.z, dir.y, -dir.x) * 90; m_LastDir = dir; m_LastMove = m_Cube.transform.position + ndir; Vector3 origin = m_Cube.transform.position; RaycastHit outHit; if (!Physics.Linecast(origin, origin + dir, out outHit)) { CubeManager.Instance.RegisterMove(this); //You can replace with iTween or any tweener you like Tweener.RotateTo(this.gameObject, transform.rotation.eulerAngles, targetRotation, m_RollSpeed, 0, Tweener.TweenerEaseType.Linear, Complete); } } }
private void DoRoll(Vector3 dir) { Vector3 ndir = Vector3.zero; if (Mathf.Abs(dir.x) == 1) { ndir = dir * m_Cube.bounds.size.x / 2f; } else if (Mathf.Abs(dir.z) == 1) { ndir = dir * m_Cube.bounds.size.z / 2f; } Vector3 newAxis = m_Cube.ClosestPointOnBounds(m_Cube.transform.position + ndir); newAxis.y = m_Cube.bounds.min.y; Vector3 thisPos = new Vector3(); thisPos = m_Cube.transform.position; Quaternion thisRot = new Quaternion(); thisRot = m_Cube.transform.rotation; transform.position = newAxis; transform.rotation = Quaternion.identity; m_Cube.transform.rotation = thisRot; m_Cube.transform.position = thisPos; Vector3 targetRotation = new Vector3(dir.z, dir.y, -dir.x) * 90; m_LastDir = dir; m_LastMove = m_Cube.transform.position + ndir; //You can replace with iTween or any tweener you like Tweener.RotateTo(this.gameObject, transform.rotation.eulerAngles, targetRotation, m_MoveSpeed, 0, Tweener.TweenerEaseType.Linear, Complete); }