void Update() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); } target = player.transform.position; if (controller.collisions.below) { velocity.y = 0; velocity.x = 0; moveSpeed = 0; targetVelocityX = 0; velocityXSmoothing = 0; currentJumpDelay -= Time.deltaTime; //anim.speed = 1.5f; //anim.SetTrigger("LANDED"); anim.SetBool("LANDED", true); } else { //anim.speed = 0.2f; anim.SetBool("LANDED", false); } //currentJumpDelay -= Time.deltaTime; if (currentJumpDelay <= 0) { moveSpeed = 250; if (target.x > transform.position.x) { //target is on right velocity.y = jumpVelocity; targetVelocityX = 1 * moveSpeed; Sprite.transform.localRotation = new Quaternion(0, 180, 0, 0); } else if (target.x < transform.position.x) { //target is on left velocity.y = jumpVelocity; targetVelocityX = -1 * moveSpeed; Sprite.transform.localRotation = new Quaternion(0, 0, 0, 0); } float jumpDelay = Random.Range(MIN_JUMP_DELAY, MAX_JUMP_DELAY); currentJumpDelay = jumpDelay; //Debug.Log(jumpDelay); velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirbourne); } velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); }
void Update() { if (player == null) { player = GameObject.FindGameObjectWithTag("Player"); } target = player.transform.position; float targetVelocityX = 0; float targetVelocityY = 0; if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } if (target.x > transform.position.x) { targetVelocityX = moveSpeed; } else if (target.x < transform.position.x) { targetVelocityX = -moveSpeed; } if (pickup) { if (target.y > transform.position.y) { targetVelocityY = moveSpeed; } else { targetVelocityY = -moveSpeed; } velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, .3f); velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocityY, ref velocityYSmoothing, .3f); controller.Move(velocity * Time.deltaTime); } else { velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, .3f); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); } }
private void Update() { base.Update(); float velOut = 0f; Velocity.y = 0f; Velocity.x = Mathf.SmoothDamp(Velocity.x, _moveSpeed, ref velOut, 0.2f); Controller2d.Move(Velocity * Time.deltaTime); }
void Update() { if (controller.collisions.above || controller.collisions.below || (controller.collisions.right && !controller.collisions.below) || (controller.collisions.left && !controller.collisions.below)) { velocity.y = 0; //we set the velocity back to 0 because we dont want the gravity force to accumulate } if (isLocalPlayer) { Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetKeyUp(KeyCode.Space)) { if (velocity.y > minJumpVelocity) { velocity.y = minJumpVelocity; timeToJumpApex = timeToJumpApex / (maxJumpHeight / minJumpHeight); //Debug.Log("velocityApres" + velocity.y); } } if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.below) { //Debug.Log("velocityFirst" + velocity.y); velocity.y = maxJumpVelocity; //Debug.Log("velocityFirst" + velocity.y); } if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.left && !controller.collisions.below) { velocity.y += maxJumpVelocity * .75f; Debug.Log("WALLJUMP"); velocity.x = Mathf.SmoothDamp(velocity.x, moveSpeed * 2 * -1, ref velocityXsmoothing, accelerationTimeAirboarne) * -1; Debug.Log(velocity.x); } if (Input.GetKeyDown(KeyCode.Space) && !controller.collisions.below && controller.collisions.right) { velocity.y += maxJumpVelocity * .75f; Debug.Log("WALLJUMP"); velocity.x = Mathf.SmoothDamp(velocity.x, moveSpeed * 2 * -1, ref velocityXsmoothing, accelerationTimeAirboarne) * -1; Debug.Log(velocity.x); } float targetVelocityX = input.x * moveSpeed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXsmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirboarne); //Adds some acceleration to the vector. Makes it feel smooth. velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); } }
// Update is called once per frame void Update() { if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } // Get movement input Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); // Handle Jump input if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.below) { velocity.y = jumpVelocity; } float targetVelocityX = input.x * moveSpeed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirborne); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); // Handle character sprites if (velocity.x > 0) { animate.StandRight(); } else if (velocity.x < 0) { animate.StandLeft(); } if (velocity.y > 0) { if (velocity.x < 0) { animate.JumpLeft(); } else { animate.JumpRight(); } } }
private new void Update() { base.Update(); FallCheck(); // Do not accumulate gravity if colliding with anythig vertical if (Controller2d.Collisions.FromBelow || Controller2d.Collisions.FromAbove) { Velocity.y = 0; } if (_actionMovement.BounceBackActive) { ApplyBounceBack(); } else { CalculateVelocityOffInput(); ApplyGravity(); Controller2d.Move(Velocity * Time.deltaTime, DirectionalInput, JoystickId); // Reset the jump indicator once we've made contact with the ground again if (_jumped && Controller2d.Collisions.FromBelow) { _jumped = false; } } CalculateMovementAnimation(); CalcualteFacingDirection(); CalculateWeaponRotation(); DevelopmentHealthHack(); CheckForUltReady(); CheckForUltimateUse(); // Check for weapon switching if (Input.GetButtonUp(JoystickId + GameConstants.Input_LBumper) || Input.GetKeyUp(InputManager.Instance.ChangeWeapon)) { _weaponManager.SwitchWeapon(); } }
void Update() { //CheckMousePos(); if (controller.collisions.above || controller.collisions.below) { velocity.y = 0; } Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); if (Input.GetKeyDown(KeyCode.Space) && controller.collisions.below) { velocity.y = jumpVelocity; } float targetVelocityX = input.x * moveSpeed; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirbourne); velocity.y += gravity * Time.deltaTime; controller.Move(velocity * Time.deltaTime); }
private void Update() { CalculateVelocity(); HandleWallSliding(); if (Input.GetKeyDown(KeyCode.I) && !controller.collisions.knockedBack) { controller.Knockback(); } if (controller.collisions.knockedBack && !controller.collisions.oldKnockBack) { velocity.x = -controller.collisions.faceDir * jumpBack.x; velocity.y = jumpBack.y; } controller.Move(velocity * Time.deltaTime, directionalInput); if (controller.collisions.below && controller.collisions.knockedBack && controller.collisions.oldKnockBack) { velocity.x = 0; controller.collisions.knockedBack = false; } if (controller.collisions.above || controller.collisions.below) { if (controller.collisions.slidingDownMaxSlope) { velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime; } else { velocity.y = 0; } } }
protected override void Move() { Animator.SetFloat("Velocity", Mathf.Abs(Velocity.x)); Controller2d.Move(Velocity * Time.deltaTime); }