public void SetFrame(int frame) { SAnimation.SetFrame(frame); }
public void DoMovement(NetworkBase.PlayerInput input) { if (!canMove) { return; } //if (NetworkControl) return; bool grounded = false; float spriteXSizeHalf = gameObject.GetComponent <SpriteRenderer>().sprite.bounds.size.x / 2f; //racasts checking if player is standing on a block, casts from both edges of hitbox RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f + new Vector2(spriteXSizeHalf - 0.05f, 0), -Vector2.up, 0.10f); //RaycastHit2D hit2 = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f - new Vector2(gameObject.GetComponent<SpriteRenderer>().sprite.bounds.size.x / 2f, 0), -Vector2.up, 0.10f); //if ((hit.transform != null && hit.transform != transform) || (hit2.transform != null && hit2.transform != transform)) // grounded = true; if (hit.transform != null && hit.transform != transform) { grounded = true; } else { RaycastHit2D hit2 = Physics2D.Raycast((Vector2)transform.position - Vector2.up * 0.20f - new Vector2(spriteXSizeHalf - 0.05f, 0), -Vector2.up, 0.10f); if (hit2.transform != null && hit2.transform != transform) { grounded = true; } } //if (!Grounded && grounded) SAnimation.PlayAnimation("Idle", Pcolor); Grounded = grounded; /* * //Quickstop before input check * if ((QuickStop && grounded) || (!grounded && QuickStopAIR)) * { * _rigid.velocity = new Vector2(0, _rigid.velocity.y); * }*/ if (grounded || AirControl) { Vector2 movement = new Vector2((_rigid.velocity.x < 0? Vector2.left.x : (_rigid.velocity.x > 0? Vector2.right.x : 0)) * MoveSpeed, _rigid.velocity.y); //if (Input.GetKey(controls == Controls.WASD ? KeyCode.A : KeyCode.LeftArrow) || InputManager.GetAxis("Horizontal", playerID) < 0) if (input.xAxis < 0) { movement.x = Vector2.left.x * MoveSpeed; LastMovedRight = false; } if (input.xAxis > 0) { movement.x = Vector2.right.x * MoveSpeed; LastMovedRight = true; } if (input.xAxis == 0) { movement.x = 0; } _rigid.velocity = movement; } if (input.JumpUp || (!grounded && _rigid.velocity.y < 0.1f && _rigid.velocity.y > -0.1f)) { _isJumping = false; holdingJump = false; // _rigid.AddForce(Vector2.down * JumpENDForceDown); //_rigid.gravityScale = 1.0f; } if (input.JumpDown || input.Jump) { if (!_isJumping && (grounded || MultipleJumps)) { jumpTimer = HoldJumpMaxSec; _isJumping = true; holdingJump = true; SAnimation.PlayAnimation("Jump", Pcolor, false, 5, 2, 0); SAnimation.SetFrame(2); //_currentJumpForce = (Physics.gravity * _rigid.mass).magnitude * 5f; _rigid.AddForce(Vector2.up * JumpForce); //ScoreManager.gameData.Jumped++; } } /* * if (input.Jump && _isJumping) holdingJump = true; * else holdingJump = false; */ }