void StartPushingEnd() { PushableObjectPad pad = pushableObject.GetComponent <PushableObjectPad>(); PushableObject pushable = pushableObject.transform.parent.GetComponent <PushableObject>(); pushingSpeed = pushingSpeed * pushable.speedMult; Vector3 endPos = rb.position + pad.endPosOffset; float inverseMoveTime = pushingSpeed / pad.endPosOffset.magnitude; pushable.Push(pad.endPosOffset, inverseMoveTime); StartCoroutine(SmoothMovement((bool done) => { anim.SetTrigger("stopPushing"); GameSound.Stop("Push"); }, endPos, inverseMoveTime)); GameSound.Play("Push"); }
/* ====================================== * * UPDATE * * ====================================== */ void Update() { //grounded = Physics2D.Linecast (transform.position, groundCheck.position, ground); //ContactFilter2D filter; //filter RaycastHit2D[] hitObjects = new RaycastHit2D[20]; grounded = (groundCollider.Cast(Vector2.zero, hitObjects) > 0) ? true : false; direction = new Vector3(0, 0, 0); if ((Input.GetKeyDown(moveRightKey) || Input.GetKeyDown(moveRightAlternativeKey)) && !isPreparingToJump) { facingRight = true; } if ((Input.GetKeyDown(moveLeftKey) || Input.GetKeyDown(moveLeftAlternativeKey)) && !isPreparingToJump) { facingRight = false; } if ((Input.GetKey(moveRightKey) || Input.GetKey(moveRightAlternativeKey)) && !isPreparingToJump) { moving = true; } else if ((Input.GetKey(moveLeftKey) || Input.GetKey(moveLeftAlternativeKey)) && !isPreparingToJump) { moving = true; } else { moving = false; } anim.SetBool("isMoving", moving); anim.SetBool("isGrounded", grounded); anim.SetBool("isHanging", hanging); if ((airControl && !grounded) || grounded) { transform.localScale = (facingRight ? new Vector3(1, 1, 1) : new Vector3(-1, 1, 1)); direction += (moving ? new Vector3(transform.localScale.x, 0, 0) : Vector3.zero); } // =============== PUSH DEBUG =================== Debug.DrawLine(transform.position, transform.position + Vector3.right * 2f); // ============ ENDOF PUSH DEBUG ================ if (Input.GetKey(crouchKey) || Input.GetKey(crouchAlternativeKey)) { currentMoveSpeed = crouchSpeed; walkCollider.enabled = false; crouchCollider.enabled = true; } else if (Input.GetKeyDown(pushKey) || Input.GetKeyDown(pushAlternativeKey)) { RaycastHit2D hit = Physics2D.Raycast(transform.position, (facingRight) ? Vector3.right : Vector3.left, 2f, pushableLayers); if (hit != null) { PushableObject pushObject = hit.transform.gameObject.GetComponent <PushableObject>(); if (pushObject != null) { pushObject.Push(transform.position); anim.SetTrigger("push"); } } } else { currentMoveSpeed = moveSpeed; walkCollider.enabled = true; crouchCollider.enabled = false; if ((Input.GetKeyDown(jumpKey) || Input.GetKeyDown(jumpAlternativeKey)) && grounded) { isPreparingToJump = true; currentJumpForce = minJumpForce; currentTime = 0f; currentTicks = 0f; } bool forceJump = false; if ((Input.GetKey(jumpKey) || Input.GetKey(jumpAlternativeKey)) && isPreparingToJump) { currentTime += Time.deltaTime; if (currentTime >= (jumpPrepareTime / numberOfTicks)) { currentJumpForce += (maxJumpForce - minJumpForce) / numberOfTicks; currentTicks++; //Debug.Log("TICK-TACK"); currentTime = 0f; } if (currentTicks == numberOfTicks) { forceJump = true; } } if (((Input.GetKeyUp(jumpKey) || Input.GetKeyUp(jumpAlternativeKey)) && grounded && isPreparingToJump) || forceJump) { isPreparingToJump = false; isJumping = true; } } }