Beispiel #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        currentGrindSpeed = grindSpeed * globalPlayerController.currentSpeedMultiplier;
        globalPlayerController.recentAction = RecentActionType.Grind;
        rb.velocity = new Vector3(0, 0, 0);

        // Debug.DrawRay(rb.position, currentRail.path.GetDirectionAtDistance (dstTravelled,  EndOfPathInstruction.Stop), Color.black, 0.01f);
        // Debug.DrawRay(rb.position, -currentRail.path.GetDirectionAtDistance (dstTravelled,  EndOfPathInstruction.Stop), Color.red, 0.01f);

        if (!isReversed)
        {
            dstTravelled += currentGrindSpeed * Time.fixedDeltaTime;
            rb.rotation   = Quaternion.LookRotation(currentRail.path.GetDirectionAtDistance(dstTravelled, EndOfPathInstruction.Stop));
        }
        else
        {
            dstTravelled      -= currentGrindSpeed * Time.fixedDeltaTime;
            transform.rotation = currentRail.path.GetRotationAtDistance(dstTravelled, EndOfPathInstruction.Stop);
            transform.rotation = Quaternion.LookRotation(-currentRail.path.GetDirectionAtDistance(dstTravelled, EndOfPathInstruction.Stop));
        }

        rb.position = currentRail.path.GetPointAtDistance(dstTravelled, EndOfPathInstruction.Stop) +
                      (currentRail.path.GetNormalAtDistance(dstTravelled) * (0.02f + roadMeshCreator.thickness + (cc.height / 2f)));

        float curTime = currentRail.path.GetClosestTimeOnPath(rb.position);

        timeOnPath = curTime;
        if (curTime > 0.99f || curTime < 0.01f)
        {
            globalPlayerController.EnableDefaultControls();
            rb.velocity = transform.forward * currentGrindSpeed;
            globalPlayerController.recentAction = RecentActionType.None;
            StartCoroutine(CoolDownTimer(0.1f));
        }


        if (globalPlayerController.input.jumpPressed && isLocalPlayer)
        {
            globalPlayerController.EnableDefaultControls();
            rb.velocity = (transform.forward + new Vector3(0, 1, 0) + (globalPlayerController.input.moveDirection * 0.4f)) * grindSpeed * 1.05f;
            globalPlayerController.IncreaseSpeedMultiplier(0.2f);
            globalPlayerController.recentAction = RecentActionType.SlideJump;
            StartCoroutine(CoolDownTimer(0.1f));
        }
        //Debug.Log(currentRail.path.GetClosestTimeOnPath (rb.position));

        globalPlayerController.input.jumpPressed = false;
        globalPlayerController.input.dashPressed = false;
    }
Beispiel #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //preparation from last physics frame
        if (gpc.recentAction != RecentActionType.OnWall)
        {
            CalculateWallNormalAndDirection();
            //cast a 45 degree angle downwards from the torso to check wall cling?
        }
        else if (!(Physics.Raycast(transform.position + (transform.up * 0.65f), transform.forward + -transform.up, 0.75f)))
        {
            DismountFromWall(true);
        }

        //wall calculations have determined we're not on a wall, and should cease
        if (!this.enabled)
        {
            return;
        }

        isWallRunning = wallRunDirection != new Vector3(0, 0, 0) && currentWallRunDuration > 0; //  && gpc.recentAction != RecentActionType.WallJump;

        //stuff to do this physics frame
        //gpc.recentAction = RecentActionType.None;

        if (isWallRunning)   //regular wall running
        {
            gpc.recentAction = RecentActionType.WallRunning;
            rb.velocity      = wallRunDirection * ((defaultWallRunSpeed * currentWallRunDuration * Mathf.Log10(gpc.currentSpeedMultiplier + wallRunLogScale)) + wallRunEndSpeed);
            gameObject.transform.rotation = Quaternion.RotateTowards(rb.rotation, Quaternion.LookRotation(rb.velocity), 540f * Time.deltaTime);
        }
        else if (wallRunDirection != new Vector3(0, 0, 0))     //ran out of running, detach from wall
        // Debug.Log("dismount as ran out of wall run time");
        // Debug.Log("wallRunDir: " + wallRunDirection);
        // Debug.Log("wallRunDuration: " + currentWallRunDuration);
        // Debug.Log("wallNormal: " +  wallNormal);
        {
            DismountFromWall(true);
        }
        else     //sliding down wall
        {
            gpc.recentAction = RecentActionType.OnWall;
            rb.AddForce(Physics.gravity * wallSlideDownSpeed);
            gameObject.transform.rotation = Quaternion.LookRotation(-wallNormal);
        }

        if (gpc.input.jumpPressed && canAct && isLocalPlayer)
        {
            if (isWallRunning)
            {
                gpc.IncreaseSpeedMultiplier(0.2f);
                rb.velocity = new Vector3(
                    rb.velocity.normalized.x + wallNormal.normalized.x + (gpc.input.moveDirection.x * 0.4f),
                    1f,
                    rb.velocity.normalized.z + wallNormal.normalized.z + (gpc.input.moveDirection.z * 0.4f)) * wallRunInitialJumpForce;
            }
            else
            {
                gpc.IncreaseSpeedMultiplier(0.1f);
                rb.velocity = new Vector3(
                    wallNormal.normalized.x + (gpc.input.moveDirection.x * 0.4f),
                    2f,
                    wallNormal.normalized.z + (gpc.input.moveDirection.z * 0.4f)).normalized *initialJumpForce * 1.25f;

                gameObject.transform.rotation = Quaternion.LookRotation(wallNormal);
            }

            gpc.recentAction = RecentActionType.WallJump;

            Debug.DrawRay(rb.position, rb.velocity, Color.blue, 2f);
            gpc.EnableDefaultControls();
        }
        else if (gpc.input.crouchPressed && isLocalPlayer)
        {
            gpc.input.crouchPressed = false;
            DismountFromWall(false);
        }


        gpc.input.jumpPressed = false;
        gpc.input.dashPressed = false;
    }