Example #1
0
    void OnTriggerStay(Collider collision)
    {
        if (collision.gameObject.name == "Ship")
        {
            forceController fc          = collision.gameObject.GetComponent <forceController>();
            Vector3         boatToWhirl = this.transform.position - collision.gameObject.transform.position;    //(new Vector3(collision.gameObject.transform.position.x, this.transform.position.y, collision.gameObject.transform.position.z) - this.transform.position);
            boatToWhirl = new Vector3(boatToWhirl.x, 0, boatToWhirl.z);
            float whirlRadius = this.transform.lossyScale.x;
            collision.gameObject.rigidbody.AddForce(boatToWhirl.normalized * Mathf.Sin((whirlRadius - boatToWhirl.magnitude) / whirlRadius * Mathf.PI / 2) * fc.forceFactor * 3);
            if (clockwise)
            {
                collision.gameObject.rigidbody.AddTorque(Vector3.up * fc.rotFactor / (whirlRadius - boatToWhirl.magnitude) * 20);
            }
            else
            {
                collision.gameObject.rigidbody.AddTorque(-Vector3.up * fc.rotFactor / (whirlRadius - boatToWhirl.magnitude) * 20);
            }

            Debug.DrawLine(this.transform.position, this.transform.position + boatToWhirl.normalized * 5);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (perlinMap == null)
        {
            perlinMap = waveMesh.GetComponent <PerlinMap>();
        }

        Vector3 nextPosition = this.transform.position + this.rigidbody.velocity * Time.deltaTime;
        float   x            = nextPosition.x;
        float   z            = nextPosition.z;

        targetHeight = perlinMap.GetHeight(x, z) + 0.08f;
        float NHeight = perlinMap.GetHeight(x, z + length / 2) + 0.08f;
        float EHeight = perlinMap.GetHeight(x + width / 2, z) + 0.08f;
        float SHeight = perlinMap.GetHeight(x, z - length / 2) + 0.08f;
        float WHeight = perlinMap.GetHeight(x - width / 2, z) + 0.08f;

        pointN = nextPosition + this.transform.forward * length / 2;
        pointN = new Vector3(pointN.x, NHeight, pointN.z);
        pointS = nextPosition - this.transform.forward * length / 2;
        pointS = new Vector3(pointS.x, SHeight, pointS.z);
        pointE = nextPosition + this.transform.right * width / 2;
        pointE = new Vector3(pointE.x, EHeight, pointE.z);
        pointW = nextPosition - this.transform.right * width / 2;
        pointW = new Vector3(pointW.x, WHeight, pointW.z);

        Vector3 NSVector = (pointN - pointS).normalized;
        Vector3 EWVector = (pointE - pointW).normalized;

        zAngle = AngleSigned(this.transform.forward, NSVector, this.transform.right);
        xAngle = AngleSigned(this.transform.right, EWVector, this.transform.forward);

        //float xAngle = AngleSigned(this.transform.right, xVector.normalized, this.transform.forward);
        //float zAngle = AngleSigned(this.transform.forward, zVector.normalized, this.transform.right);

        Debug.DrawLine(pointW, pointE, Color.red);
        Debug.DrawLine(pointS, pointN, Color.blue);

        //Vector3 targetRotation = new Vector3(zAngle, this.transform.rotation.y, xAngle);

        //Quaternion qX = Quaternion.AngleAxis(xAngle, this.transform.forward);
        //Quaternion qZ = Quaternion.AngleAxis(zAngle, this.transform.right);
        //this.transform.localRotation = qX * qZ;

        //this.transform.Rotate(this.transform.forward, xAngle - this.transform.eulerAngles.x);
        //this.transform.Rotate(this.transform.right, zAngle - this.transform.eulerAngles.z);
        //Debug.Log(zAngle);

        Vector3 localVelocity = this.transform.InverseTransformDirection(this.rigidbody.velocity);

        if (this.gameObject.tag == "Player")
        {
            forceController fc = this.gameObject.GetComponent <forceController>();
            if (sinking)
            {
                fc.enabled = false;
            }
            else
            {
                if (localVelocity.z >= 0f)
                {
                    if (wakeSystemL != null && wakeSystemR != null)
                    {
                        wakeSystemL.emissionRate = 500f * Mathf.Abs(fc.curSpeed / fc.maxSpeed);
                        wakeSystemR.emissionRate = 500f * Mathf.Abs(fc.curSpeed / fc.maxSpeed);
                    }
                }
            }
        }
        else if (this.gameObject.tag == "Enemy")
        {
            enemyController fc = this.gameObject.GetComponent <enemyController>();
            if (sinking)
            {
                fc.enabled = false;
            }
            else
            {
                if (localVelocity.z >= 0f)
                {
                    if (wakeSystemL != null && wakeSystemR != null)
                    {
                        wakeSystemL.emissionRate = 500f * Mathf.Abs(fc.curSpeed / fc.maxSpeed);
                        wakeSystemR.emissionRate = 500f * Mathf.Abs(fc.curSpeed / fc.maxSpeed);
                    }
                }
            }
        }

        if (this.transform.position.y <= -2f)
        {
            Destroy(this.gameObject);
        }
    }
Example #3
0
 // Use this for initialization
 void Start()
 {
     forcer = BoatBoat.GetComponent <forceController>();
     forcer.allOars.Add(this);
 }