// Update is called once per frame void FixedUpdate() { isGrounded = ec.IsTouchingLayers(platformLayer); isBouncing = ec.IsTouchingLayers(bouncerLayer); if (Input.GetAxis("Horizontal") != 0) { rb.velocity = new Vector2(playerSpeed * Input.GetAxis("Horizontal"), rb.velocity.y); } if (Input.GetAxis("Vertical") > 0) { if (isGrounded) { rb.velocity = new Vector2(rb.velocity.x, jumpForce); } } if (Input.GetAxis("Vertical") < 0) { transform.localScale = new Vector3(1, 0.5f, 1); } else { transform.localScale = new Vector3(1, 1, 1); } if (isBouncing) { rb.velocity = new Vector2(rb.velocity.x, jumpForce * 1.25f); } }
private void OnTriggerEnter2D(Collider2D collision) { if (edgeCollider2D.IsTouchingLayers(simonLayer) && !isChanging && SimonActions.simon.CanTrasint()) { isChanging = true; CameraMovement currentCamera = Camera.main.GetComponent <CameraMovement>(); currentCamera.ChangeCameraMovement(); if (!bossScenario) { LeftCollider.enabled = false; RigthCollider.enabled = false; } else { LeftCollider.enabled = true; RigthCollider.enabled = true; StartCoroutine(GameManager.gameManager.SpawnBoss()); } if (doorTransit) { currentCamera.transitCamera = true; } if (holeTransit) { StartCoroutine(GameManager.gameManager.ClosePassage()); } StartCoroutine(GameManager.gameManager.WaitForTransition()); if (bossScenario) { edgeCollider2D.enabled = false; } } }
void Update() { if (transform.position.y < FALL_CUTOFF) { Destroy(gameObject); return; } if (dead) { transform.Rotate(new Vector3(0, 0, 1), Time.deltaTime * 1000); return; } if (!edgeFinder.IsTouchingLayers(LayerMask.GetMask("Ground"))) { turnAround(); } walkDelay -= Time.deltaTime; if (walkDelay <= 0) { Vector2 vel = rb.velocity; vel.x = WALK_SPEED; if (rb.transform.localScale.x < 0) { vel.x = -vel.x; } rb.velocity = vel; walkDelay = WALK_DELAY; } }
private bool IsGrounded() { foreach (string name in names) { if (box.IsTouchingLayers(LayerMask.GetMask(name))) { return(true); } } return(false); }
// Update is called once per frame void Update() { bool isTouchingWall = edgeCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")); bool isTouchingGround = feetCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")); if (isTouchingWall || !isTouchingGround) { FlipSprite(); } MoveEnemy(); }
private IEnumerator Reloud() { yield return(new WaitForSeconds(1.0f)); toPosition = fromPosition; fromPosition = transform.position; T = 0; if (activateByPlayer && !state && !edgecollider.IsTouchingLayers(LayerMask.GetMask("Player"))) { yield break; } move = true; }
private void Run() { float controlThrow2 = Input.GetAxis("Vertical"); // value is between -1 to +1 if (!myAnimator.GetBool("Sliding") && !myAnimator.GetBool("Crouch") && controlThrow2 != -1 && canRun) { float controlThrow = Input.GetAxisRaw("Horizontal"); // value is between -1 to +1 Vector2 playerVelocity = new Vector2(controlThrow * runSpeed, myRigidbody.velocity.y); myRigidbody.velocity = playerVelocity; bool stateOfRunning = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon; if (myfeetCollider.IsTouchingLayers() && health > 0) { if (!isSwordDrawed) { myAnimator.SetBool("Running", stateOfRunning); } else { myAnimator.SetBool("DrawSwordRunning", stateOfRunning); } } } }
private void FixedUpdate() { CurrentVelocity = GetSpeed() * LastDirection; CurrentVelocity = Mathf.Clamp(CurrentVelocity, -MaxSpeed, MaxSpeed); _canJump = AirVelocity < 0 && Physics2D.Raycast(transform.position, Vector2.down, MinJumpDistance, GroundLayers); _isGrounded = GroundDetector.IsTouchingLayers(GroundLayers) || Physics2D.Raycast(transform.position, Vector2.down, MinGroundDistance, GroundLayers); Body.velocity = new Vector2(CurrentVelocity, AirVelocity) * Time.fixedDeltaTime; if (Time.time - LastMoveTime > MoveTime) { LastDirection = 0; CurrentVelocity = 0; } }
private bool isGrounded() { // If its not in the jumping if (_rb.velocity.y <= 0) { foreach (LayerMask lm in jumpableLayers) { if (_feet.IsTouchingLayers(lm)) { _anim.ResetTrigger("Jump"); _anim.SetBool("Land", false); return(true); } } } return(false); }
private void FireAtPlayer() { if (lCannon.IsTouchingLayers(LayerMask.GetMask("Player")) && !lReload) { playerInSights = true; EquipProjectile(); myCannons.FireLeftCannon(equippedItem); StartCoroutine("ReloadLeft"); lReload = true; } else if (rCannon.IsTouchingLayers(LayerMask.GetMask("Player")) && !rReload) { playerInSights = true; EquipProjectile(); myCannons.FireRightCannon(equippedItem); StartCoroutine("ReloadRight"); rReload = true; } else { playerInSights = false; } }
bool isTouchingGround( ) { return(groundDetector.IsTouchingLayers(groundLayers) || Physics2D.Raycast(transform.position, Vector2.down, minGroundDistance, groundLayers)); }
// Update is called once per frame void FixedUpdate() { if (_isAdjusting) { Adjust(_nextPos); } if (panArea.IsTouchingLayers(layerMask)) { switch (myDirection) { case panDirection.pan01: //check if pan02 is active if not set active Camera_Parent.PANLINES[1].SetActive(true); _curSpeed = _speed; _targetPos = setPos((_level.right), player.transform.position.x - 3.3f) + getCameraPosition(panDirection.pan01); //_nextPos = setPos((_level.right), player.transform.position.x-2.8f) + getCameraPosition(panDirection.pan01); Follow(_targetPos, _curSpeed); step = 0; _curPos = _level.transform.position; // _isAdjusting = true; break; case panDirection.pan02: //check if pan01 is active if not set active Camera_Parent.PANLINES[0].SetActive(true); _curSpeed = _speed; _targetPos = setPos((_level.right), player.transform.position.x + 3.3f) + getCameraPosition(panDirection.pan01); // _nextPos = setPos((_level.right), player.transform.position.x - 1f) + getCameraPosition(panDirection.pan01); _curPos = _level.transform.position; Follow(_targetPos, _curSpeed); //_isAdjusting = true; break; case panDirection.pan03: //make pan01 inactive Camera_Parent.PANLINES[0].SetActive(false); break; case panDirection.pan04: //make pan02 inactive Camera_Parent.PANLINES[1].SetActive(false); break; case panDirection.pan05: _curSpeed = _speed; _targetPos = setPos((_level.up), player.transform.position.y - 1.8f) + getCameraPosition(panDirection.pan05); // _nextPos = setPos((_level.up), player.transform.position.y + 1f) + getCameraPosition(panDirection.pan05); _curPos = _level.transform.position; Follow(_targetPos, _curSpeed); // _isAdjusting = true; break; case panDirection.pan06: _curSpeed = _speed; _targetPos = setPos((_level.up), player.transform.position.y + 1.8f) + getCameraPosition(panDirection.pan05); // _nextPos = setPos((_level.up), player.transform.position.y - 1f) + getCameraPosition(panDirection.pan05); _curPos = _level.transform.position; Follow(_targetPos, _curSpeed); // _isAdjusting = true; break; } } }