Esempio n. 1
0
    private void ResolvePlaneCollision()
    {
        float d1 = plane.DistanceTo(transform.position) - radiusOfSphere;

        velocity           += accelleration * Time.deltaTime;
        transform.position += velocity * Time.deltaTime;

        if (plane != null)
        {
            float distanceFromCenterToPlane = plane.DistanceTo(transform.position);
            float d2 = distanceFromCenterToPlane - radiusOfSphere;

            //determine the distance between
            Vector3 pra  = ParComp(velocity, plane.normal);
            Vector3 perp = PerpComp(velocity, plane.normal);

            float timeOfImpact = Time.deltaTime * (d1 / (d1 - d2));

            transform.position -= velocity * (Time.deltaTime - timeOfImpact);

            velocity = perp - coefficientOfRestitution * pra;

            transform.position += velocity * (Time.deltaTime - timeOfImpact);
        }
    }
    // Update is called once per frame
    void Update()
    {
        float d1 = plane.DistanceTo(transform.position) - radius;

        Velocity           += Accelleration * Time.deltaTime;
        transform.position += Velocity * Time.deltaTime;
        float distanceFromCenterToPlane = plane.DistanceTo(transform.position);
        float d2 = distanceFromCenterToPlane - radius;

        if (d2 <= 0)
        {
            Vector3 para = ParallellComp(Velocity, plane.NormalToPlane);
            Vector3 perp = PerpendicularComp(Velocity, plane.NormalToPlane);

            float timeOfImpact = Time.deltaTime * (d1 / (d1 - d2));
            transform.position -= Velocity * (Time.deltaTime - timeOfImpact);

            Velocity = perp - coefficiantOfRestitution * para;

            transform.position += Velocity * (Time.deltaTime - timeOfImpact);
        }
    }