コード例 #1
0
ファイル: CamController.cs プロジェクト: nickworks/LetsGo
    private void Ease()
    {
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        if (h == 0 && v == 0)
        {
            velocity = Vector3.zero;
        }
        else
        {
            velocity += transform.forward * v * Time.deltaTime * accelerationMultiplier;
            velocity += transform.right * h * Time.deltaTime * accelerationMultiplier;
        }
        if (velocity.sqrMagnitude > maxSpeed * maxSpeed)
        {
            velocity = velocity.normalized * maxSpeed;
        }
        offset += velocity * Time.deltaTime;

        Vector3 center = play ? play.GetCenter() : Vector3.zero;
        Vector3 pos    = center + offset;

        if (play && !play.GetBounds().Contains(pos))
        {
            Vector3 newpos = play.GetBounds().ClosestPoint(pos);
            if (newpos.x != pos.x)
            {
                velocity.x = 0;
            }
            if (newpos.y != pos.y)
            {
                velocity.y = 0;
            }
            if (newpos.z != pos.z)
            {
                velocity.z = 0;
            }
            pos    = newpos;
            offset = pos - center;
        }
        transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * moveEasing);
    }