CalculatePositionAndRotationOnMesh() public method

public CalculatePositionAndRotationOnMesh ( float progressionOnMesh, float widthOffset, Vector3 &calculatedPos, Quaternion &calculatedRot, float &calculatedHeightValue ) : void
progressionOnMesh float
widthOffset float
calculatedPos Vector3
calculatedRot Quaternion
calculatedHeightValue float
return void
Beispiel #1
0
    void Update()
    {
        Vector3 tempPos = transform.position;

        Vector3    calPos          = Vector3.zero;
        Quaternion calRot          = Quaternion.identity;
        float      newHeightOffset = 0;

        // updated based on velocities
        widthOffset += relativeVelocity.x * Time.deltaTime;
        widthOffset  = Mathf.Clamp(widthOffset, -meshlineWidth * 0.5f, meshlineWidth * 0.5f);
        float relativeLocationOnLine = 0.5f + widthOffset / meshlineWidth;


        // move rider forward before looking for closest meshline
        progressionOnMesh += relativeVelocity.z * Time.deltaTime;
        progressionOnMesh  = Mathf.Clamp(progressionOnMesh, 0, 0.9f);

        meshlinesGenerator.CalculatePositionAndRotationOnMesh(progressionOnMesh, relativeLocationOnLine, out calPos, out calRot, out newHeightOffset);

        HandleNewHeight(newHeightOffset);

        transform.position  = calPos;        // set base meshline postion
        transform.rotation  = calRot;
        transform.position += transform.right * widthOffset;
        transform.position += transform.up * heightOffset;


        // apply friction to velocities
        //relativeVelocity -=  linearVelocityDecay * relativeVelocity * Time.deltaTime;

        if (wasSidePressed == false)
        {
            relativeVelocity.x -= linearVelocityDecay * relativeVelocity.x * Time.deltaTime;
            if (Mathf.Abs(relativeVelocity.x) < 0.01f)
            {
                relativeVelocity.x = 0;
            }
        }
        if (wasForwardPressed == false)
        {
            relativeVelocity.z -= linearVelocityDecay * relativeVelocity.z * Time.deltaTime;
        }

        wasSidePressed    = false;
        wasForwardPressed = false;
    }