public override void UpdateMotor(CharacterMover mover) { //apply Friction float speed = mover.velocity.magnitude; if (speed != 0) //avoid dividing by zero { float drop = speed * mover.friction * Time.deltaTime; mover.velocity *= Mathf.Max(speed - drop, 0) / speed; //scale the velocity based on friction. } mover.velocity = mover.Accelerate(mover.accelDir, mover.velocity, mover.groundAccel, mover.maxGroundSpeed); //jumping if (mover.kpJump) { mover.velocity = new Vector3(mover.velocity.x, mover.jumpSpeed, mover.velocity.z); mover.gravity = new Vector3(0f, mover.gSpeed, 0f); } //floor no longer beneath us, switch state if (!mover.IsGrounded()) { mover.currentState = MovementState.falling; Debug.Log("Switch to falling"); } }
public override void UpdateMotor(CharacterMover mover) { //variable height if (mover.krJump && mover.velocity.y > 0f) { mover.gravity = new Vector3(0f, mover.gSpeedVariable, 0f); } if (mover.velocity.y <= 0f) { //if (mover.wallSlide) // mover.gravity= new Vector3(0f, mover.gSpeed/5, 0f); //else mover.gravity = new Vector3(0f, mover.gSpeed, 0f); } mover.velocity += mover.gravity * Time.deltaTime; mover.wallSlide = false; mover.velocity = mover.Accelerate(mover.accelDir, mover.velocity, mover.airAccel, mover.maxAirSpeed); //mover.charController.Move (mover.velocity); if (mover.IsGrounded()) { mover.velocity = new Vector3(mover.velocity.x, 0f, mover.velocity.z); mover.currentState = MovementState.walking; mover.wallSlide = false; mover.gravity = new Vector3(0f, mover.gSpeed, 0f); Debug.Log("Switch to walking"); } }
public override TaskStatus OnUpdate() { { //while we are more than X distance from target node Vector2 ourPos = transform.position; float difX = Mathf.Abs(nextPos.x - ourPos.x); float difY = ourPos.y - nextPos.y; // || if platform above or below blocks us from nextPos if (this.path == null) { Debug.Log("task failed"); //10.16.16, no alternate behavior specified on task failure ... this.path = null; return(TaskStatus.Failure); } //Still moving towards target if (difX > .1f || difY > minYOffset) { float horizontalInput = 0; bool verticalInput = false; //Check if x movement necessary if (Mathf.Abs(nextPos.x - ourPos.x) > .1f) { horizontalInput = nextPos.x - ourPos.x; } //Check if jump necessary ==== if (controller.IsGrounded()) { //if next <= ourPos.y and trajectory of no jump does not pass over if (nextPos.y < ourPos.y && !trajectoryPrediction.doesTrajectoryPassOver(Mathf.Sign(nextPos.x - ourPos.x) * controller.moveSpeed, 0, ourPos, nextPos)) { verticalInput = true; } //else if next is above our current position else if (nextPos.y > ourPos.y) { verticalInput = true; } } controller.setInput(horizontalInput, verticalInput); return(TaskStatus.Running); } //If reached nextNode, get next node to move towards else if ((difX < .25f && Physics2D.Linecast(ourPos, nextPos + Vector2.up, 1 << LayerMask.NameToLayer("Environment"))) || path.Next != null) { controller.setInput(0, false); if (controller.IsGrounded()) { return(TaskStatus.Success); } return(TaskStatus.Running); } //Done, no target path found else { controller.setInput(0, false); return(TaskStatus.Success); } } }