Beispiel #1
0
    public override void CollideWithWave(WavePositionInfo waveInfo)
    {
        Vector3 position        = rb.position;
        Vector3 colFootPosition = position + Vector3.down * footDist;

        float waveOverlap = waveInfo.position.y - colFootPosition.y;

        if (waveOverlap < 0f)
        {
            return;
        }

        /*
         * SINKING
         *
         * Use a maxSinkDepth value to make sure we never sink the camera below the sand.
         * Essentially transition footDepth from 0-maxSinkDepth over time
         *
         * TODO: need to implement respawning at some point
         */

        // TODO: alter logic based on lightsensor status (Sink)
        bool isLit = lightSensor.GetCurrentIntensity() > 0f;

        // Tell jumpCollider player is grounded
        if (isLit)
        {
            jumpCollider.Grounded(true);
        }

        // inside wave volume
        if (waveOverlap > footDepth)
        {
            // move rigidbody to align with surface
            rb.MovePosition(position + Vector3.up * (waveOverlap - footDepth));
        }

        Vector3 velocity = rb.velocity;

        if (Vector3.Dot(velocity.normalized, waveInfo.normal) < 0f)
        {
            Vector3 velocityAlongWaveNormal = Vector3.Project(velocity, waveInfo.normal);
            rb.velocity -= velocityAlongWaveNormal;
        }

        // Dampen velocity while in contact
        if (velocityDampenStrength > 0f)
        {
            rb.velocity *= 1 - (Time.fixedDeltaTime * velocityDampenStrength);
        }
    }