// Update is called once per frame protected override void SpaxUpdate() { if (!stopTimer.IsTicking()) { StateConditions curCond = data.GetStateConditions(); //for holding change in velocity for faster access float accel = 0f; //holds the x-axis input for faster access int xInput = input.X(); //if there is a frame to apply some stuff, do it //if the state allows for gravity application if ((curCond & StateConditions.APPLY_GRAV) > 0) { if ((calcVelocity.y - data.GetGravForce()) <= (-1 * data.moveStats.maxFallSpeed)) { calcVelocity.y = -1 * data.moveStats.maxFallSpeed; } else { calcVelocity.y -= data.GetGravForce(); } } //read if the player wants to move if (xInput != 0) { //if the state allows for movement if ((curCond & StateConditions.CAN_MOVE) > 0) { bool isWalking = (curCond & StateConditions.WALKING) == StateConditions.WALKING; //hold the acceleration for quicker access accel = data.GetAcceleration(isWalking); //Debug.Log(isWalking+" | "+accel); if (FPMath.Abs(calcVelocity.x + accel * xInput) >= (FP)data.GetMaxSpeed(isWalking)) { calcVelocity.x = data.GetMaxSpeed(isWalking) * xInput; } else { calcVelocity.x += accel * xInput; } } } //if the state applies friction if ((curCond & StateConditions.APPLY_FRICTION) > 0) { //accel will be (at least) close to 0 if the player an and wants to move if (Mathf.Abs(accel) < 0.00001f) { //hold the friction for quicker access accel = data.GetFriction(); if ((FPMath.Abs(calcVelocity.x) - accel) <= 0f) { calcVelocity.x = 0f; } else { //multiply by normalized to counter the current velocity calcVelocity.x -= accel * calcVelocity.normalized.x; } } } //assign the new calculated velocity to the rigidbody rb.velocity = calcVelocity; //txt.text = data.GetStringPrevInputs(); } }