void FixedUpdate() { if (!SonoSuPiattaforma) { GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player. GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1 } else { //if(input.x != ) } if (groundState.isWall() && !groundState.isGround() && input.y == 1) { GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction) if (photonView.isMine && PlayerNetwork.possoMorire) { photonView.RPC("SuonoSalto", PhotonTargets.All); } } if (groundState.isGround() && input.y == 1 && photonView.isMine && PlayerNetwork.possoMorire) { photonView.RPC("SuonoSalto", PhotonTargets.All); } anim.SetFloat("Speed", Mathf.Abs(input.x)); anim.SetBool("IsGrounded", groundState.isGround()); anim.SetFloat("vSpeed", GetComponent <Rigidbody2D>().velocity.y); input.y = 0; }
void FixedUpdate() { int wallDir = groundState.wallDirection(); //Direction of the wall: 1 is right and -1 is left bool grounded = isGrounded(); //True if the player is touching the ground taking count of the cayote time bool walled = (wallDir != 0); //True if the player is touching a wall rb.AddForce(new Vector2(((input.x * speed) - rb.velocity.x) * ((grounded && !walled) ? accelleration : airaccelleration) * (walled ? 1 : accellerationMultiplier), (rb.velocity.y < -0.05 && !walled) ? Physics2D.gravity.y * (fallingMultiplayer - 1): 0)); //Move player. If the player is falling, add more fall to the falling (depends on the falling Multiplaier) //Stop player if input.x is 0 (and grounded) //Jump if the player is pressing Jump (And grounded or walled) //If the player is pressing the jump key in air, it keeps jumping high. If the player stops holding the jump key, his air velocity gets reduced. rb.velocity = new Vector2((input.x == 0 && grounded) ? 0 : rb.velocity.x, (input.y == 1 && (grounded || walled)) ? jump : (jumping || rb.velocity.y < 0) ? rb.velocity.y : rb.velocity.y / 2); if (walled && !grounded && input.y == 1) { rb.velocity = new Vector2(-wallDir * speed * wallJumpMultiplier, rb.velocity.y); //Add force negative to wall direction (with speed reduction) } //Handels the Sound of Jumping if (input.y == 1 && (walled || grounded)) { SoundManager.soundManager.PlaySingle(jumpClip); } input.y = 0; }
void FixedUpdate() { GetComponent <Rigidbody2D>().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D>().velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player. GetComponent <Rigidbody2D>().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D>().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D>().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1 if (groundState.isWall() && !groundState.isGround() && input.y == 1) { GetComponent <Rigidbody2D>().velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, GetComponent <Rigidbody2D>().velocity.y); //Add force negative to wall direction (with speed reduction) } input.y = 0; }
void FixedUpdate() { if (!canMove) { return; } Dash(); rb.AddForce(new Vector2(((input.x * speed) - rb.velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player. rb.velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : rb.velocity.x, (input.y == 1 && groundState.isTouching()) ? jumpForce : rb.velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1 if (groundState.isWall() && !groundState.isGround() && input.y == 1) { rb.velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, rb.velocity.y); //Add force negative to wall direction (with speed reduction) } input.y = 0; }
void FixedUpdate() { if (GetComponent <CharacterStats>().knockBack) { return; } if (direction == 0) { GetComponent <Rigidbody2D> ().AddForce(new Vector2(((input.x * speed) - GetComponent <Rigidbody2D> ().velocity.x) * (groundState.isGround() ? accel : airAccel), GetComponent <Rigidbody2D> ().velocity.y)); //Move player. } if ((groundState.isGround() || groundState.isWall()) && input.x != 0 || input.y != 0) { canDash = true; } GetComponent <Rigidbody2D> ().velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : GetComponent <Rigidbody2D> ().velocity.x, (input.y == 1 && groundState.isTouching()) ? jump : GetComponent <Rigidbody2D> ().velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1 if (groundState.isWall() && input.y == 1) { GetComponent <Rigidbody2D> ().velocity = new Vector2(-groundState.wallDirection() * speed * 1.3f, GetComponent <Rigidbody2D> ().velocity.y); //Add force negative to wall direction (with speed reduction) } input.y = 0; }
void FixedUpdate() { Debug.Log(TestPrintState()); ourBody.AddForce(new Vector2(((input.x * speed) - ourBody.velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player. ////Stop player if input.x is 0 (and grounded) ////jump if input.y is 1 if (input.y == 1 && groundState.isTouching()) { if (groundState.isWall()) { yvelocity = walljump; } else { yvelocity = jump; } } else { yvelocity = ourBody.velocity.y; } ourBody.velocity = new Vector2( (input.x == 0 && groundState.isGround()) ? 0 : ourBody.velocity.x, (yvelocity)); //Walljump if (groundState.isWall() && !groundState.isGround() && input.y == 1) { Debug.Log("YVelocity: " + ourBody.velocity.y); ourBody.velocity = new Vector2(-groundState.wallDirection() * speed * 0.95f, ourBody.velocity.y); //Add force negative to wall direction (with speed reduction) } input.y = 0; }
void FixedUpdate() { if (!levelController.levelStarted) //if level hasn't started { if (inputHorizontal != 0 || inputJumpDown != 0 || inputJumpHeld != 0 || inputDash != 0) { levelController.LevelStarted(); } } if (!levelController.levelCompleted) //if level hasnt been completed { //Sprite Rotation //Sprite desired rotation based on input if (inputHorizontal != 0) { if (inputHorizontal < 0) { charFacingLeft = true; } else if (inputHorizontal > 0) { charFacingLeft = false; } } //Check if a rotation needed if (!spriteFacingLeft && charFacingLeft) { rotationNeeded = true; //if facing left is false and player is going left a rotation is needed } else if (spriteFacingLeft && !charFacingLeft) { rotationNeeded = true; //if facing left is true and player is going right a rotation is needed } else { rotationNeeded = false; //otherwise the player is rotated the right way } //if there is a rotation needed if (rotationNeeded && charFacingLeft) //rotate the sprite to the left and update the bool { transform.localRotation = Quaternion.Euler(0, 0, 0); spriteFacingLeft = true; } else if (rotationNeeded && !charFacingLeft) //rotate the sprite to the right and update the bool { transform.localRotation = Quaternion.Euler(0, 180, 0); spriteFacingLeft = false; } //Wall Slide Check if (!groundState.isGround() && groundState.isWall()) { charWallSliding = true; } else { charWallSliding = false; } //Dashing if (groundState.isGround()) { charDashAvailable = true; } if (!groundState.isGround() && inputDash == 1 && charDashAvailable && !charDashing && charJumpTime >= charDashJumpBufffer) //Dash { animator.SetBool("Dashing", charDashing); //signal dashing has begun for animator charDashing = true; //player is dashing charDashAvailable = false; //disable the player from dashing again if (charWallSliding) { //take horizontal direction - if they are wallsliding - perform opposite dash dir if (charFacingLeft && inputHorizontal != -1) { charDashDir = 1; //if left, dash right } else if (!charFacingLeft && inputHorizontal != 1) { charDashDir = -1; //if right dash left } } else { //if not wall sliding if (charFacingLeft) { charDashDir = -1; //if left dash left } else { charDashDir = 1; //if right dash right } } charJumping = false; //disable the player variable jumping charPreDashVelocity = rb.velocity.x; //save the players velocity before the dash rb.gravityScale = 0; //disable gravity rb.velocity = new Vector2(charDashDir * charDashSpeed, 0); } else if (charDashing) //If the player is in the middle of a dash //Continue dashing with dash deceleration until the speed reaches the speed of the player before the dash { rb.velocity = new Vector2(rb.velocity.x - (charDashDir * charDashDecel), rb.velocity.y); if (charDashDir == 1) { //dash is to the right if (rb.velocity.x <= charPreDashVelocity || rb.velocity.x <= -charPreDashVelocity) //if the player has slowed to their pre-dash velocity { charDashing = false; } //return the gravity to normal } else if (charDashDir == -1) { //dash is to the left if (rb.velocity.x >= charPreDashVelocity || rb.velocity.x >= -charPreDashVelocity) //if the player has slowed to their pre-dash velocity { charDashing = false; } //return the gravity to normal } if (!charDashing) { charDashing = false; rb.gravityScale = 2; } } else //if player has not started a dash or is not dashing //Then apply normal movement- walking, jumping etc.. { //reset dash values charDashDir = 0; charPreDashVelocity = 0; //Walking Movement //Move player by the speed value multiplied by ground or air acceleration rb.AddForce(new Vector2(((inputHorizontal * charSpeed) - rb.velocity.x) * (groundState.isGround() ? charAccel : charAirAccel), 0)); //Stop player if input.x is 0 (and grounded) rb.velocity = new Vector2((inputHorizontal == 0 && groundState.isGround()) ? 0 : rb.velocity.x, rb.velocity.y); //Jumping //See if the player has jumped if ((charJumpDelayTimer > Time.time || inputJumpDown == 1) && (groundState.isGround() || groundState.isWall())) //if jump is pressed for the first time and touching the ground or wall { charJumping = true; //character has started jumping charJumpDurationLeft = charJumpDuration; //reset the jump time charJumpDelayTimer = 0; rb.velocity = new Vector2(rb.velocity.x, charJumpForce); //make the character jump if (!groundState.isGround()) //if player is not touching the ground (wall jump) { charWallDirection = groundState.wallDirection(); if (charWallDirection == -1) { charFacingLeft = false; //left } else if (charWallDirection == 1) { charFacingLeft = true; //right } rb.velocity = new Vector2(-charWallDirection * charSpeed * 0.75f, rb.velocity.y); //Add force negative to wall direction (with speed reduction) animator.SetTrigger("WallJumped"); //signal wall jump for the animator } else { charJumped = true; charJumpTime = 0; //reset jump time animator.SetTrigger("GroundJumped"); //signal char jumped to animator (ground jump) } } else if (inputJumpHeld == 1 && charJumping == true) //jump is held and jumping hasnt ended by player letting go of jump { //check if jump time hasnt ended yet and the player isnt stuck on ceiling forcing them to have 0 .y velocity if (charJumpDurationLeft > 0 && rb.velocity.y > 0) { rb.velocity = new Vector2(rb.velocity.x, charJumpForce); //make the character jump charJumpDurationLeft -= Time.deltaTime; //reduce the jump time } } if (charJumped) { if (charJumpTime >= charDashJumpBufffer) { if (groundState.isGround()) { charJumped = false; rb.velocity = new Vector2(rb.velocity.x, 0); } } charJumpTime += Time.deltaTime; } else { if (!groundState.isGround()) { charJumpTime += Time.deltaTime; } } //if the jumping input stops set jumping to false if (inputJumpHeld == 0) { charJumping = false; } } } else //level completed { rb.velocity = new Vector2(0, 0); } //Animation values //send values to the animator animator.SetFloat("VelocityY", rb.velocity.y); animator.SetBool("WallSliding", charWallSliding); animator.SetBool("Dashing", charDashing); //check if the input of the horizontal axis is negative if (inputHorizontal < 0) { animator.SetFloat("InputHorizontal", inputHorizontal * -1); //send to animator } else { animator.SetFloat("InputHorizontal", inputHorizontal); //otherwise send the positive value } //check if the velocity of the rb is negative if (rb.velocity.x < 0) { animator.SetFloat("VelocityX", rb.velocity.x * -1); //make the velocity positive and send it to the animator } else { animator.SetFloat("VelocityX", rb.velocity.x); //otherwise send the positive value } animator.SetBool("Grounded", groundState.isGround()); if (inputHorizontal == 0 && groundState.isGround()) { stoppedMoving = true; } else { stoppedMoving = false; } animator.SetBool("Stopped", stoppedMoving); //Variable Reset //resetting input values inputHorizontal = 0; inputJumpDown = 0; inputJumpHeld = 0; inputDash = 0; }