void Attack() { if (Input.GetMouseButtonDown(0) && IsGrounded()) { _animScript.Attack(); } }
void Update() { Movement(); if (CrossPlatformInputManager.GetButtonDown("A_Button") && IsGrounded() == true) //Input.GetMouseButtonDown(0) { _playerAnim.Attack(); } }
private void Update() { Movement(); CheckGrounded(); if (Input.GetMouseButtonDown(0) && grounded) { playerAnim.Attack(); } }
// Update is called once per frame void Update() { GetInput(); if (takingMoveInput) { if (sliding || afterSlide) { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(new Vector3(vel.x, 0f, vel.z)), Time.deltaTime * currentTurnSpeed); } else { if (moveInputMagnitude > 0.3)//rotating the character { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(moveDir), Time.deltaTime * currentTurnSpeed); } } if (isChargeShooting) { if (isGrounded) { vel = Vector3.zero; } } else { if (isGrounded) { if (rolling) { vel = moveDir * rollSpeed; jumpVel = RB.velocity.y; } else if (sliding) { Vector3 vec = Vector3.Cross(slopeVector, Vector3.up).normalized; //vel = (moveDir * moveInputMagnitude * slideControl * Mathf.Abs(Vector3.Dot(moveDir, vec))) + (slopeVector * slideSpeed); vel = (vec * Vector3.Dot(moveDir, vec) * moveInputMagnitude * slideControl) + (slopeVector * slideSpeed); jumpVel = RB.velocity.y + (slopeVector.y * slideSpeed); //jumpVel = RB.velocity.y; } else if (afterSlide) { vel = RB.velocity; jumpVel = (slopeVector.y * slideSpeed); } else { if (moveInputMagnitude > 0.6) { vel = moveDir * moveInputMagnitude * walkSpeed; } else { vel = Vector3.zero - (slopeVector * 1.6f); } jumpVel = RB.velocity.y; } } else { if (rolling) { EndRoll(); } if (enableAirControl && (RB.velocity.magnitude < airControlMaxSpeed || Vector3.Dot(moveDir, RB.velocity.normalized) < 0.5f)) { RB.AddForce(moveDir.x * airControl * moveInputMagnitude, 0f, moveDir.z * airControl * moveInputMagnitude); } vel = RB.velocity; jumpVel = RB.velocity.y; } } } lVel = Vector3.Lerp(RB.velocity, vel, currentFriction); if (currentFriction < maxMoveFriction) { currentFriction = Mathf.Lerp(currentFriction, maxMoveFriction, Time.deltaTime * 1f); } if (Input.GetButtonDown("Jump"))//|| rolling)) // OPTION { if (isGrounded && !hasJumped && takingJumpInput || isMounted) { if (canRollJump) { EndRoll(); } Jump(); //hasJumped = false; } } if (canRoll && Input.GetButtonDown("Roll") && isGrounded && takingMoveInput && !sliding) { ExecuteRoll(); } if (isGrounded) { if (leftground) // happenes on landing { GameManager.Instance.cameraShake.Shake(0.1f, 0.1f, 0.4f); hasJumped = false; canAirAttack = true; } else { hasJumped = false; } leftground = false; } else { if (!leftground && hasJumped) { leftground = true; } else if (!leftground && !hasJumped) { leftground = true; } SetJumpVel(); if (Physics.Raycast((transform.position + (transform.forward * 0.2f)) + (transform.up * 0.5f), transform.forward, 0.5f)) { enableAirControl = false; } else { enableAirControl = true; } } if (Input.GetButtonDown("Fire1") && !rolling && !sliding && !isMounted) { /*if(!isGrounded && canAirAttack) * { * if (RB.velocity.y < 0f) * { * jumpVel = 0f; * RB.AddForce(Vector3.up * 10f * (-RB.velocity.y*0.03f), ForceMode.Impulse); * } * canAirAttack = false; * playerAnim.Attack(); * } * else if(isGrounded) * { * playerAnim.Attack(); * }*/ playerAnim.Attack(); } RaycastHit hit; if (!isMounted) { if (Physics.Raycast(transform.position + (transform.up * 0.1f), Vector3.down, out mainHit, 0.25f) && (Physics.Raycast((transform.position + (transform.forward * 0.2f)) + (transform.up * 0.1f), Vector3.down, out hit, 0.25f) || Physics.Raycast((transform.position + (transform.forward * -0.2f)) + (transform.up * 0.1f), Vector3.down, out hit, 0.25f) || Physics.Raycast((transform.position + (transform.right * 0.2f)) + (transform.up * 0.1f), Vector3.down, out hit, 0.25f) || Physics.Raycast((transform.position + (transform.right * -0.2f)) + (transform.up * 0.1f), Vector3.down, out hit, 0.25f))) { isGrounded = true; if (hit.collider.gameObject.layer != LayerMask.NameToLayer("Solid"))//hit.collider.gameObject.isStatic == false) // perant to not static objects / maybe switch to the two point parant system from cyberlight // done { //transform.parent = hit.collider.transform; if (resetAnchorCounter > 0.2f) { resetAnchorCounter = 0f; ResetAnchor(); } else { resetAnchorCounter += Time.deltaTime; if (anchorPoint.transform.parent == null)// || hit.collider.transform != anchorPoint.transform.parent.transform) { //transform.position = hit.point; anchorPoint.transform.position = mainHit.point; anchorPoint.transform.parent = mainHit.collider.transform; anchorPointFollow.transform.position = anchorPoint.transform.position; transform.parent = anchorPointFollow.transform; } } //transform.position = anchorPointFollow.transform.position; //transform.parent = anchorPointFollow.transform; } else { transform.parent = null; anchorPoint.transform.parent = null; anchorPoint.transform.position = transform.position; } groundVector = hit.normal; slopeVector = Vector3.Cross(-Vector3.Cross(groundVector, Vector3.up), groundVector); if (hit.collider.tag == "SlipperySlope" && checkForSliding)//slideAngle <= (Vector3.Angle(Vector3.up, slopeVector) - 90f) && checkForSliding) { sliding = true; afterSlide = true; afterSlideCounter = 0f; } else { if (afterSlide) { if (afterSlideCounter > afterSlideTime) { afterSlide = false; afterSlideCounter = 0f; } afterSlideCounter += Time.deltaTime; } sliding = false; } //Debug.Log(Vector3.Angle(Vector3.up, slopeVector)-90f); //Debug.DrawLine(hit.point, hit.point + slopeVector,Color.red); } else { afterSlide = false; isGrounded = false; transform.parent = null; anchorPoint.transform.parent = null; anchorPoint.transform.position = transform.position; sliding = false; } } //Debug.Log(isGrounded); }
public void Attack() { _myAnimations.Attack(); _weapon.enabled = true; StartCoroutine("attackTime"); }