// Update is called once per frame void Update() { // Set input data for easy access SetInputVariables(); // Reset Gravity rb.gravityScale = 3; // Use the statemachine StateMachine(currentState); // Can enter the climbing state from any state // You may want to move this depending on the states you add if (coll.onWall && Input.GetButton("Fire2") && canMove) { // Change state currentState = PlayerState.CLIMBING; // Flips sprite based on which wall if (side != coll.wallSide) { anim.Flip(side * -1); } // Bools for movement and animation wallGrab = true; wallSlide = false; } // Used when no longer on a wall if (Input.GetButtonUp("Fire2") || !coll.onWall || !canMove) { wallGrab = false; wallSlide = false; } // When on the ground and not dashing // You might want to move these to a state if (coll.onGround && !isDashing) { wallJumped = false; GetComponent <BetterJumping>().enabled = true; } // When on the wall and not on the gorund if (coll.onWall && !coll.onGround) { // If the player is moving towards the wall if (xInput != 0 && !wallGrab) { // Slide down the wall wallSlide = true; WallSlide(); } } // If not on the wall and on the ground // Maybe move this to IDLE? if (!coll.onWall || coll.onGround) { wallSlide = false; } // Jump when hitting the space bar if (coll.onGround && isDashing) { isDashing = false; hasDashed = false; } if (coll.onGround && !isDashing) { isDashing = false; hasDashed = false; } // When you have left the ground if (!coll.onGround && groundTouch) { groundTouch = false; } // Return if on a wall if (wallGrab || wallSlide || !canMove) { return; } // Otherwise use the horizontal input to flip the sprite if (xInput > 0) { side = 1; anim.Flip(side); } if (xInput < 0) { side = -1; anim.Flip(side); } }
// Update is called once per frame void Update() { float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); float xRaw = Input.GetAxisRaw("Horizontal"); float yRaw = Input.GetAxisRaw("Vertical"); float xpos = rb.position.x; // Player x position float ypos = rb.position.y; // Player y position float run = rb.velocity.x; // Player x velocity if (run > 7) { run = 7; } Vector2 dir = new Vector2(x, y); OSCHandler.Instance.SendMessageToClient("pd", "/unity/xpos", xpos); OSCHandler.Instance.SendMessageToClient("pd", "/unity/ypos", ypos); OSCHandler.Instance.SendMessageToClient("pd", "/unity/run", 1 - (Math.Abs(run) / 10)); // Only play walking noise if player is on the ground if (coll.onGround && !isOnGround) { OSCHandler.Instance.SendMessageToClient("pd", "/unity/grounded", "ready"); isOnGround = true; } else if (!coll.onGround && isOnGround) { OSCHandler.Instance.SendMessageToClient("pd", "/unity/grounded", "ready"); isOnGround = false; } var main = ps.main; main.simulationSpeed = particleSpeed / 40; main.startSize = (float)((particleSize - 26) * .015); Walk(dir); anim.SetHorizontalMovement(x, y, rb.velocity.y); if (coll.onWall && Input.GetButton("Fire3") && canMove) { if (side != coll.wallSide) { anim.Flip(side * -1); } wallGrab = true; wallSlide = false; } if (Input.GetButtonUp("Fire3") || !coll.onWall || !canMove) { wallGrab = false; wallSlide = false; } if (coll.onGround && !isDashing) { wallJumped = false; GetComponent <BetterJumping>().enabled = true; } if (wallGrab && !isDashing) { rb.gravityScale = 0; if (x > .2f || x < -.2f) { rb.velocity = new Vector2(rb.velocity.x, 0); } float speedModifier = y > 0 ? .5f : 1; rb.velocity = new Vector2(rb.velocity.x, y * (speed * speedModifier)); } else { rb.gravityScale = 3; } if (coll.onWall && !coll.onGround) { if (x != 0 && !wallGrab) { wallSlide = true; WallSlide(); } } if (!coll.onWall || coll.onGround) { wallSlide = false; } if (Input.GetButtonDown("Jump")) { anim.SetTrigger("jump"); if (coll.onGround) { Jump(Vector2.up, false); } if (coll.onWall && !coll.onGround) { WallJump(); } } // Play dash distortion when player dashed. if (Input.GetButtonDown("Fire1") && !hasDashed) { OSCHandler.Instance.SendMessageToClient("pd", "/unity/dash", 100); if (xRaw != 0 || yRaw != 0) { Dash(xRaw, yRaw); } } if (coll.onGround && !groundTouch) { GroundTouch(); groundTouch = true; } if (!coll.onGround && groundTouch) { groundTouch = false; } WallParticle(y); if (wallGrab || wallSlide || !canMove) { return; } if (x > 0) { side = 1; anim.Flip(side); } if (x < 0) { side = -1; anim.Flip(side); } }
void Update() { otherPlayer.transform.position = transform.position; if (Input.GetMouseButtonDown(1)) { otherPlayer.SetActive(true); gameObject.SetActive(false); } float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); float xRaw = Input.GetAxisRaw("Horizontal"); float yRaw = Input.GetAxisRaw("Vertical"); Vector2 dir = new Vector2(x, y); walk(dir); anim.SetHorizontalMovement(x, y, rb.velocity.y); if (coll.onGround && !isDashing) { wallJumped = false; GetComponent <playerJump>().enabled = true; } if (wallGrab && !isDashing) { rb.gravityScale = 0; if (x > .2f || x < -.2f) { rb.velocity = new Vector2(rb.velocity.x, 0); } float speedModifier = y > 0 ? .5f : 1; rb.velocity = new Vector2(rb.velocity.x, y * (movementSpeed * speedModifier)); } else { rb.gravityScale = 1.5f; } if (Input.GetButtonDown("Jump")) { anim.SetTrigger("jump"); if (coll.onGround) { jump(Vector2.up); } if (coll.onWall && !coll.onGround) { WallJump(); } } if (Input.GetButtonDown("Fire1") && !hasDashed) { if (xRaw != 0 || yRaw != 0) { Dash(xRaw, yRaw); } } if (coll.onWall && !coll.onGround) { if (x != 0) { wallSlide = true; WallSlide(); } } if (coll.onGround && !groundTouch) { GroundTouch(); groundTouch = true; } if (!coll.onGround && groundTouch) { groundTouch = false; } if (!coll.onWall || coll.onGround) { wallSlide = false; } if (wallSlide || !canMove) { return; } if (x > 0) { side = 1; anim.Flip(side); } if (x < 0) { side = -1; anim.Flip(side); } }
// Update is called once per frame void Update() { float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); float xRaw = Input.GetAxisRaw("Horizontal"); float yRaw = Input.GetAxisRaw("Vertical"); Vector2 dir = new Vector2(x, y); Walk(dir); anim.SetHorizontalMovement(x, y, rb.velocity.y); if (coll.onWall && Input.GetButton("Fire3") && canMove) { if (side != coll.wallSide) { anim.Flip(side * -1); } wallGrab = true; wallSlide = false; } if (Input.GetButtonUp("Fire3") || !coll.onWall || !canMove) { wallGrab = false; wallSlide = false; } if (coll.onGround && !isDashing) { wallJumped = false; GetComponent <BetterJumping>().enabled = true; } if (wallGrab && !isDashing) { rb.gravityScale = 0; if (x > .2f || x < -.2f) { rb.velocity = new Vector2(rb.velocity.x, 0); } float speedModifier = y > 0 ? .5f : 1; rb.velocity = new Vector2(rb.velocity.x, y * (speed * speedModifier)); } else { rb.gravityScale = 3; } if (coll.onWall && !coll.onGround) { if (x != 0 && !wallGrab) { wallSlide = true; WallSlide(); } } if (!coll.onWall || coll.onGround) { wallSlide = false; } if (Input.GetButtonDown("Jump")) { anim.SetTrigger("jump"); if (coll.onGround) { Jump(Vector2.up, false); } if (coll.onWall && !coll.onGround) { WallJump(); } } if (Input.GetButtonDown("Fire1") && !hasDashed) { if (xRaw != 0 || yRaw != 0) { Dash(xRaw, yRaw); } } if (coll.onGround && !groundTouch) { GroundTouch(); groundTouch = true; } if (!coll.onGround && groundTouch) { groundTouch = false; } WallParticle(y); if (wallGrab || wallSlide || !canMove) { return; } if (x > 0) { side = 1; anim.Flip(side); } if (x < 0) { side = -1; anim.Flip(side); } }
// Update is called once per frame void Update() { // Set input data for easy access SetInputVariables(); // Reset Gravity rb.gravityScale = 3; // Use the statemachine StateMachine(currentState); if (Input.GetKeyDown(KeyCode.N)) { Debug.Log(currentState); } // When on the ground and not dashing // You might want to move these to a state if (coll.onGround && !isDashing) { wallJumped = false; GetComponent <BetterJumping>().enabled = true; } // If not on the wall and on the ground // Maybe move this to IDLE? if (!coll.onWall || coll.onGround) { wallSlide = false; } // When you land on the ground if (coll.onGround && !groundTouch) { // GroundTouch() resets the dash, as you can only dash once per jump GroundTouch(); groundTouch = true; } // When you have left the ground if (!coll.onGround && groundTouch) { groundTouch = false; } // Return if on a wall if (wallGrab || wallSlide || !canMove) { return; } // Otherwise use the horizontal input to flip the sprite if (xInput > 0) { side = 1; anim.Flip(side); } if (xInput < 0) { side = -1; anim.Flip(side); } }
// Update is called once per frame void Update() { // Set input data for easy access SetInputVariables(); // Reset Gravity rb.gravityScale = 3; // Use the statemachine StateMachine(currentState); if (Input.anyKeyDown) { Debug.Log(currentState); } // If left click and if dash is not on cooldown if (Input.GetButtonDown("Fire1") && !hasDashed) { // As long as there is some directional input if (xRaw != 0 || yRaw != 0) { // Dash using raw input values Dash(xRaw, yRaw); } } // Can enter the climbing state from any state // You may want to move this depending on the states you add if (coll.onWall && Input.GetButton("Fire2") && canMove) { // Flips sprite based on which wall if (side != coll.wallSide) { anim.Flip(side * -1); } // Bools for movement and animation wallGrab = true; wallSlide = false; // Change state currentState = PlayerState.CLIMBING; } // Return if on a wall if (wallGrab || wallSlide || !canMove) { return; } // Otherwise use the horizontal input to flip the sprite if (xInput > 0) { side = 1; anim.Flip(side); } if (xInput < 0) { side = -1; anim.Flip(side); } // This code may need to stay outside of the states // Since IDLE, RUNNING, JUMPING, FALLING all still need to use this code }