예제 #1
0
    private bool IsColliding(FGPhysicsBody body)
    {
        if (WillBeCollision(body) == false)
        {
            return(false);
        }

        return(Distance(body) >= 0f || Mathf.Abs(Distance(body)) <= body.Radius);
    }
예제 #2
0
    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;
    }
예제 #3
0
    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)));
        }
    }
예제 #4
0
 private Vector3 CorrectedPosition(FGPhysicsBody body)
 {
     return(Projection(body) + Normal * body.Radius);
 }
예제 #5
0
    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);
    }
예제 #6
0
    public bool IsBodyStaticOnPlane(FGPhysicsBody body)
    {
        bool lowVelocity = RelativeVelocity(body).magnitude < m_StaticBodyVelocityLimit;

        return(lowVelocity && TouchingThePlane(body));
    }
예제 #7
0
    private float Distance(FGPhysicsBody body)
    {
        Vector3 bodyToPlane = transform.position - body.transform.position;

        return(Vector3.Dot(bodyToPlane, Normal));
    }
예제 #8
0
 private Vector3 RelativeVelocity(FGPhysicsBody body)
 {
     return(body.Velocity - ParentVelocity);
 }
예제 #9
0
 private bool WillBeCollision(FGPhysicsBody body)
 {
     return(Vector3.Dot(RelativeVelocity(body), Normal) < 0f);
 }
예제 #10
0
 private void InverseRelativeVelocity(FGPhysicsBody body, Vector3 vel)
 {
     body.Velocity = vel + 2f * ParentVelocity;
 }
예제 #11
0
    private Vector3 Projection(FGPhysicsBody body)
    {
        Vector3 bodyToProjection = Distance(body) * Normal;

        return(body.transform.position + bodyToProjection);
    }