public static bool TryCollide(GObject b1, GObject b2) { // b1.m_PhysBody.PrintCoords(); // b2.m_PhysBody.PrintCoords(); m_VcTemp.x = Mathf.Abs(b1.GetX() - b2.GetX()) - b2.GetWidth(); m_VcTemp.y = Mathf.Abs(b1.GetY() - b2.GetY()) - b2.GetHeight(); if (m_VcTemp.x > 0 || m_VcTemp.y > 0) { return(false); } // if ( Mathf.Abs(b1.GetX() - b2.GetX()) > b1.GetWidth()/2 + b2.GetWidth()/2) return false; // if ( Mathf.Abs(b1.GetY() - b2.GetY()) > b1.GetHeight()/2 + b2.GetHeight()/2) return false; return(true); }
void Bounce(GObject entity) { m_VcTemp.x = m_Transform.position.x - entity.GetX(); m_VcTemp.y = m_Transform.position.y - entity.GetY(); m_VcTemp2.x = Mathf.Abs(m_VcTemp.x) - entity.GetWidth(); m_VcTemp2.y = Mathf.Abs(m_VcTemp.y) - entity.GetHeight(); // Debug.Log("m_VcTemp" + m_VcTemp); // Debug.Log("m_VcTemp2 " + m_VcTemp2); if (m_VcTemp2.y > m_VcTemp2.x) { // Debug.Log("x"); Impulse(m_MoveDir.x, m_MoveDir.y * (-1)); } else { // Debug.Log("y"); Impulse(m_MoveDir.x * (-1), m_MoveDir.y); } // Debug.Log("_._ m_MoveDir" + m_MoveDir); m_VcTemp.Normalize(); m_Value = Mathf.Abs(Mathf.Max(m_VcTemp2.x, m_VcTemp2.y)); // Debug.Log("m_Value" + m_Value); m_VcTemp3 = m_Transform.position; m_VcTemp3.x += m_VcTemp.x * m_Value; m_VcTemp3.y += m_VcTemp.y * m_Value; // Debug.Log("m_VcTemp3" + m_VcTemp3); m_Transform.position = m_VcTemp3; }