private bool IsColliding(FGPhysicsBody body) { if (WillBeCollision(body) == false) { return(false); } return(Distance(body) >= 0f || Mathf.Abs(Distance(body)) <= body.Radius); }
void Start() { m_MainCamera = Camera.main; m_PhysicBody = GetComponent <FGPhysicsBody>(); Assert.IsNotNull(m_PhysicBody, "No FGPhysicBody script found on golfball"); Assert.IsNotNull(m_AimTool, "No aimtool assigned in editor"); m_LastBallPosition = transform.position; Cursor.lockState = CursorLockMode.Locked; }
private void Shock(FGPhysicsBody body) { if (IsColliding(body) == false) { return; } ; if (IsBodyStaticOnPlane(body)) { body.transform.position = CorrectedPosition(body); body.ApplyForce(-body.Mass * Physics.gravity); } else { body.transform.position = CorrectedPosition(body); InverseRelativeVelocity(body, Reflect(RelativeVelocity(body))); } }
private Vector3 CorrectedPosition(FGPhysicsBody body) { return(Projection(body) + Normal * body.Radius); }
private bool TouchingThePlane(FGPhysicsBody body) { float deltaMove = Mathf.Max(m_DeltaMoveCoef * body.Radius, RelativeVelocity(body).magnitude *Time.fixedDeltaTime); return((CorrectedPosition(body) - body.transform.position).magnitude <= m_CorrectedPostionCoef * deltaMove); }
public bool IsBodyStaticOnPlane(FGPhysicsBody body) { bool lowVelocity = RelativeVelocity(body).magnitude < m_StaticBodyVelocityLimit; return(lowVelocity && TouchingThePlane(body)); }
private float Distance(FGPhysicsBody body) { Vector3 bodyToPlane = transform.position - body.transform.position; return(Vector3.Dot(bodyToPlane, Normal)); }
private Vector3 RelativeVelocity(FGPhysicsBody body) { return(body.Velocity - ParentVelocity); }
private bool WillBeCollision(FGPhysicsBody body) { return(Vector3.Dot(RelativeVelocity(body), Normal) < 0f); }
private void InverseRelativeVelocity(FGPhysicsBody body, Vector3 vel) { body.Velocity = vel + 2f * ParentVelocity; }
private Vector3 Projection(FGPhysicsBody body) { Vector3 bodyToProjection = Distance(body) * Normal; return(body.transform.position + bodyToProjection); }