Exemple #1
0
    void FixedUpdate()
    {
        bool newInWater = transform.position.y < waves.getHeightAtPoint(transform.position);

        if (newInWater != inWater && newInWater == true)
        {
            velocity = rigidbody.velocity;
            splashSound.Play();
        }

        //Cast fish back
        if (fishOutOfWater && deployed && newInWater && newInWater != inWater && fishAttached != null)
        {
            unDeploy();
            DetachFish();
        }

        inWater         = newInWater;
        canBeUndeployed = inWater;

        if (inWater && deployed)
        {
            rigidbody.useGravity = false;
            rigidbody.AddForce(new Vector3(0, waterGravity, 0));
            velocity += new Vector3(0, waterGravity, 0) * Time.deltaTime;

            rigidbody.isKinematic = true;
            if (velocity.magnitude > maxSpeed)
            {
                velocity = velocity.normalized * maxSpeed;
            }
            transform.position += velocity * Time.deltaTime;
        }
        else
        {
            rigidbody.useGravity  = true;
            rigidbody.isKinematic = false;
        }
    }
Exemple #2
0
 // Update is called once per frame
 void Update()
 {
     transform.up       = waves.getNormalAtPoint(transform.position);
     transform.position = new Vector3(basePosition.x, waves.getHeightAtPoint(transform.position), basePosition.z) + transform.up * heightAboveWater;
 }