/// <summary> /// 碰撞逻辑检测 /// 调用相应的碰撞方法 /// </summary> public void OnCollision(UserData collision) { isColliderMethodEnter = true; if (isColliderStay == false) { OnColliderEnter?.Invoke(collision); isColliderStay = true; } if (isColliderStay) { OnColliderStay?.Invoke(collision); } }
public void Update() { //老版 物理碰撞 if (isColliderStay == true && isColliderMethodEnter == false) { isColliderStay = false; OnColliderExit?.Invoke(null); } //Log.Trace("物理碰撞 持续数量" + contactActors.Count); //新版物理碰撞 if (contactActors.Count > 0) { foreach (var i in contactActors) { //持续伤害 OnColliderStay?.Invoke(i); //Log.Trace("物理碰撞 持续" + i); } } //附上值 angleVelocity_copy = m_body.AngularVelocity; LinearVelocity_copy = m_body.LinearVelocity; Torque_copy = m_body.GetTorque(); Damping_copy = m_body.LinearDamping; isColliderMethodEnter = false; //Force_copy = m_body.GetForce(); //if(Force_copy.LengthSquared() > 1000000) //{ // Force_copy.Normalize(); // Force_copy = Force_copy * 31.62277660168379f; //} Force_copy_copy = Force_copy; m_body.AddForce(Force_copy); //Log.Trace("已经添加力量:" + m_body.GetForce()+" "+Force_copy); //Log.Trace("Update Mass" + m_body.Mass); Force_copy = Vector2.Zero; TickFlag(); }
private void ProcessEvents(bool colliding) { if (colliding) { triggerCollider = closestHit.collider; } if (colliding && wasColliding) // Stay { OnColliderStay?.Invoke(triggerCollider); } else if (colliding && !wasColliding) // Enter { OnColliderEnter?.Invoke(triggerCollider); } else if (!colliding && wasColliding) // Leave { OnColliderLeave?.Invoke(triggerCollider); } wasColliding = colliding; }