示例#1
0
    void Update()
    {
        // Get look input

        var dx = Input.GetAxis("Look Horizontal " + playerIndex) * control;
        var dy = Input.GetAxis("Look Vertical " + playerIndex) * control;
        var dz = Input.GetAxis("Look Roll " + playerIndex) * control;

        dx           *= dx * Mathf.Sign(dx);
        dy           *= dy * Mathf.Sign(dy);
        dz           *= dz * Mathf.Sign(dz);
        dx           += spinOutVector.x * spinOutFactor;
        dy           += spinOutVector.y * spinOutFactor;
        dz           += spinOutVector.z * spinOutFactor;
        spinOutFactor = Mathf.Max(spinOutFactor - 0.25F, 0);

        // Change the target look orientation based on the user's camera control input
        // and slowly interpolate this parent object's rotation to it based on the lookDrag

        var s = lookSpeed * Time.deltaTime * (2F + moveBoost) / 3F;

        lookTarg *= Quaternion.AngleAxis(dx * s, -Vector3.up);
        lookTarg *= Quaternion.AngleAxis(dy * s, -Vector3.forward);
        lookTarg *= Quaternion.AngleAxis(dz * s, -Vector3.right);
        transform.localRotation = Quaternion.Slerp(transform.localRotation, lookTarg, lookDrag);

        // Change the ship's look orientation as well

        s = shipLookSpeed;

        var shipLookTarg = Quaternion.identity;

        shipLookTarg *= Quaternion.AngleAxis(dx * s, -Vector3.up);
        shipLookTarg *= Quaternion.AngleAxis(dy * s, -Vector3.forward);
        shipLookTarg *= Quaternion.AngleAxis(dz * s, -Vector3.right);
        shipLook      = Quaternion.Slerp(shipLook, shipLookTarg, shipLookDrag);

        // Finally, set the position and rotation of the ship model
        // This includes a little bit of permutation for when the ship is idle

        s = Mathf.Max(0, 1 - body.velocity.magnitude * 0.05F);

        float hOff     = playerIndex * 5F;
        var   rotHover = Quaternion.identity;

        rotHover *= Quaternion.Euler(Mathf.Sin(Time.time * 2F + hOff) * 2 * s, 0, 0);
        rotHover *= Quaternion.Euler(0, Mathf.Cos(Time.time * 1.5F + hOff) * 3 * s, 0);
        rotHover *= Quaternion.Euler(0, 0, Mathf.Sin(Time.time * 2.5F + hOff) * s);
        var posHover = Vector3.zero;

        posHover.x         += Mathf.Cos(Time.time * 1.5F + hOff) * 0.03F * s;
        posHover.y         += Mathf.Sin(Time.time * 2.5F + hOff) * 0.03F * s;
        posHover.z         += Mathf.Cos(Time.time * 2F + hOff) * 0.015F * s;
        model.localPosition = posHover;

        model.rotation  = body.rotation;
        model.rotation *= shipLook;
        model.rotation *= Quaternion.Euler(0, turn, 0);
        model.rotation *= Quaternion.Euler(roll + moveBoostRoll, 0, 0);
        model.rotation *= modelRot;
        model.rotation *= rotHover;
        model.rotation *= Quaternion.Euler(spinOutFactor * 30, spinOutFactor * 30, spinOutFactor * 30);

        // Slowly center the camera over time

        camPos = Vector3.Lerp(camPos, camTargPos, camDrag * Time.deltaTime);
        camRot = Quaternion.Slerp(camRot, camTargRot, camDrag * Time.deltaTime);
        cam.transform.localPosition = camPos + new Vector3(rumble * 2F, -rumble * 0.25F, 0);
        Vector3 jitter = Random.insideUnitSphere;

        jitter.Scale(new Vector3(rumble * 0.075F, rumble * 0.075F, rumble * 0.075F));
        cam.transform.localPosition += jitter;
        cam.transform.localRotation  = camRot;

        // Rotate the armature

        armatureBase.rotation = Quaternion.identity;

        armature[0].rotation = model.rotation * Quaternion.Euler(270, 180, 0);
        for (int i = 1; i < armature.Length; i++)
        {
            float      speed       = 1 + body.velocity.magnitude * 0.2F;
            Quaternion permutation = Quaternion.Euler(Mathf.Sin(Time.time * 3F + i * 2) * speed,
                                                      Mathf.Cos(Time.time * 4F + i * 5) * speed * 2,
                                                      Mathf.Sin(Time.time * 5F + i * 7) * speed * 2);
            if (armature[i].name.Contains("_"))
            {
                permutation *= Quaternion.Euler(0, dy * -20, dx * -20);
                permutation *= Quaternion.Euler(0, 0, Mathf.DeltaAngle(turn, turnTarg));
            }
            armature[i].rotation = model.rotation * armatureRots[i] * permutation;
        }

        // Point the arrow

        arrow.pointAt(game.getCheckpointPos(playerIndex), transform.localRotation * Vector3.up);
    }