예제 #1
0
 // Use this for initialization
 void Start()
 {
     rigid = GetComponent <Rigidbody>();
     rigid.maxAngularVelocity     = float.PositiveInfinity;
     Physics.solverIterationCount = 100;
     gravityField = GetComponent <AffectedByGravityFields>();
 }
예제 #2
0
    void OnTriggerExit(Collider c)
    {
        AffectedByGravityFields f = c.GetComponent <AffectedByGravityFields>();

        if (f != null)
        {
            c.GetComponent <Rigidbody>().useGravity = true;
            f.SetGravity(false, Vector3.zero, 0);
        }
    }
예제 #3
0
    void ImpartVelocity(Rigidbody rigidbody, Vector3 throwVel, Vector3 throwAngularVel)
    {
        //find the gravity direction

        if (rigidbody.GetComponent <AffectedByGravityFields>())
        {
            AffectedByGravityFields grav = rigidbody.GetComponent <AffectedByGravityFields>();
            if (grav.isInGravityField)
            {
                Vector3 finalVel = Vector3.zero;
                if (grav.gravityDirection == new Vector3(1, 0, 0))
                {
                    finalVel = new Vector3(throwVel.x > 0 ? 0 : (throwVel.x * Settings.ThrowScale.x), throwVel.y * Settings.ThrowScale.y, throwVel.z * Settings.ThrowScale.z);
                }
                else if (grav.gravityDirection == new Vector3(-1, 0, 0))
                {
                    finalVel = new Vector3(throwVel.x < 0 ? 0 : (throwVel.x * Settings.ThrowScale.x), throwVel.y * Settings.ThrowScale.y, throwVel.z * Settings.ThrowScale.z);
                }
                else if (grav.gravityDirection == new Vector3(0, 1, 0))
                {
                    finalVel = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y > 0 ? 0 : (throwVel.y * Settings.ThrowScale.y), throwVel.z * Settings.ThrowScale.z);
                }
                else if (grav.gravityDirection == new Vector3(0, -1, 0))
                {
                    finalVel = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y < 0 ? 0 : (throwVel.y * Settings.ThrowScale.y), throwVel.z * Settings.ThrowScale.z);
                }
                else if (grav.gravityDirection == new Vector3(0, 0, 1))
                {
                    finalVel = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y * Settings.ThrowScale.y, throwVel.z > 0 ? 0 : (throwVel.z * Settings.ThrowScale.z));
                }
                else if (grav.gravityDirection == new Vector3(0, 0, -1))
                {
                    finalVel = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y * Settings.ThrowScale.y, throwVel.z < 0 ? 0 : (throwVel.z * Settings.ThrowScale.z));
                }
                else
                {
                    finalVel = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y * Settings.ThrowScale.y, throwVel.z * Settings.ThrowScale.z);
                }

                rigidbody.angularVelocity = throwAngularVel;
                rigidbody.velocity        = finalVel;
            }
            else
            {
                rigidbody.angularVelocity = throwAngularVel;
                rigidbody.velocity        = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y < 0 ? 0 : (throwVel.y * Settings.ThrowScale.y), throwVel.z * Settings.ThrowScale.z) * VarsTracker.clubHitModifier;
            }
        }
        else
        {
            rigidbody.angularVelocity = throwAngularVel;
            rigidbody.velocity        = new Vector3(throwVel.x * Settings.ThrowScale.x, throwVel.y < 0 ? 0 : (throwVel.y * Settings.ThrowScale.y), throwVel.z * Settings.ThrowScale.z) * VarsTracker.clubHitModifier;
        }
    }
예제 #4
0
    void OnTriggerStay(Collider c)
    {
        AffectedByGravityFields f = c.GetComponent <AffectedByGravityFields>();

        if (f != null)
        {
            if (f.currentGravLevel < gravLevel)
            {
                c.GetComponent <Rigidbody>().useGravity = false;
                f.SetGravity(true, isZeroGrav ? Vector3.zero : transform.up, gravLevel);
            }
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        //orient the marker in the correct direction
        AffectedByGravityFields ballGrav = ball.GetComponent <AffectedByGravityFields>();
        Vector3 markerDirection          = -ballGrav.gravityDirection;

        if (markerDirection == Vector3.zero && !ballGrav.isInGravityField)
        {
            markerDirection = Vector3.up;
        }

        transform.position = ball.transform.position + (markerDirection * 1.8f);
        transform.up       = markerDirection;
        Vector3 oldEuler = image.localEulerAngles;

        image.LookAt(player);
        Vector3 newEuler = image.localEulerAngles;

        image.localEulerAngles = new Vector3(oldEuler.x, newEuler.y, oldEuler.z);
    }