void HandleJumping() { if (Input.GetButtonDown("Jump") && canJump && (TouchingAndAboveWalkable() || TouchingClimbable())) { // In case you need to jump off a climbable that may be keeping you // from moving horizontally if (isClimbing) { canMoveHorizontally = true; rigidbody.gravityScale = baseGravityScale; //Debug.Log("Player jumped and no longer climbing"); isClimbing = false; animator.SetBool("Climbing", isClimbing); } canJump = false; // ^ avoid infinite jump glitch // The actual jumping starts here jumpCoroutine = AdjustableHeightJump(); StartCoroutine(jumpCoroutine); Jumped.Invoke(); } }
private void PerformJump() { solidBody.Stop(); solidBody.ApplyForce(new ForceArgs(null, null, Vector2.up * jumpSpeed)); UpdateCount(); Jumped?.Invoke(); }
public static Genome mutate(Genome a) { int rand = UnityEngine.Random.Range(0, a.jumps.Count); float avg = 0; foreach (Jumped j in a.jumps) { avg += j.distanceToNearestCactus.x; } if (avg == 0) { avg = 0.7f; } else { avg /= a.jumps.Count; } Jumped randJump = new Jumped { nearestCactus = null, distanceToNearestCactus = new Vector2(avg + UnityEngine.Random.Range(-0.5f, 1.0f), 0.0f) }; a.jumps.Insert(rand, randJump); return(a); }
private void Update() { _targetVelocity = new Vector2(Input.GetAxis("Horizontal"), 0); if (_targetVelocity.x < 0) { BeganWalking?.Invoke(); IsWalkingLeft = true; ChangeDirection?.Invoke(); } else if (_targetVelocity.x == 0) { StoppedWalking?.Invoke(); } else { BeganWalking?.Invoke(); IsWalkingLeft = false; ChangeDirection?.Invoke(); } if (Input.GetKey(KeyCode.Space) && Grounded) { Jumped?.Invoke(); } }
void LateUpdate() { if (Input.GetButtonDown("Jump") && groundCheck.isGrounded) { rigidbody.AddForce(Vector3.up * 100 * jumpStrength); Jumped?.Invoke(); } }
public void PrepareSuperJump(float superJumpSpeed) { _vertSpeed = superJumpSpeed; VertMovement(); _superJumped = true; _justJumped = true; Jumped?.Invoke(); }
void LateUpdate() { if (Input.GetButtonDown("Jump") && groundCheck.isGrounded) { // jumpStrength = playerStatistics.PlayerJumpPower; rigidbody.AddForce(Vector3.up * 100 * jumpStrength); Jumped?.Invoke(); } }
void LateUpdate() { // Jump when the Jump button is pressed and we are on the ground. if (Input.GetButtonDown("Jump") && (!groundCheck || groundCheck.isGrounded)) { rigidbody.AddForce(Vector3.up * 100 * jumpStrength); Jumped?.Invoke(); } }
private void Jump(Vector3 direction) { if (_canJump) { Jumped?.Invoke(direction); StartCoroutine(MoveAxis(EaseOut, _speed, gameObject, direction)); _canJump = false; } }
void LateUpdate() { if (Input.GetButtonDown("Jump") && groundCheck.isGrounded) { rigidbody.AddForce(Vector3.up * 3 * jumpStrength, ForceMode.Impulse); Jumped?.Invoke(); Invoke("AlterGravity", 0.5f); } }
private void Jump() { if (_isGrounded) { Jumped.InvokeSafe(this); _isGrounded = false; _rigidBody.AddForce(Vector2.up * _vForce); } }
public PlayerInput2D( InputActionReference moveAction, InputActionReference jumpAction) { MoveAction = moveAction; JumpAction = jumpAction; MoveAction.action.performed += UpdateMoveInputVector; MoveAction.action.canceled += UpdateMoveInputVector; JumpAction.action.performed += cbt => Jumped?.Invoke(); }
private void CheckIfJustJumped() { if (_justJumped) { Jumped?.Invoke(); _isGrounded = false; //Debug.Log("Jumped"); } else { CheckForRamp(); } }
/// <summary> /// Update the instance . /// </summary> private void Update() { //No space . if (!Input.GetKeyDown("space")) { return; } //On space jump . if (Jumped != null) { Jumped.Invoke(); } }
private void Jump() { if (jumpRequested && isGrounded) { Jumped?.Invoke(moonJumpGround); groundCheckDistance = 0.0f; StartCoroutine(ResetGroundProbe()); isGrounded = false; var jumpForce = moonJumpGround ? moonJumpVelocity : jumpVelocity; velocity += contactNormal * jumpForce; velocity.y = Mathfs.Clamp(velocity.y, 0.0f, jumpForce); } jumpRequested = false; }
public void CharacterMove(Vector3 movementDirection) { if (allowInput) { // Flatten the input to ensure horizontal movement. flattenedMovementDirection = movementDirection; flattenedMovementDirection.Scale(new Vector3(1, 1, 0)); if (flattenedMovementDirection.sqrMagnitude != 1) { flattenedMovementDirection.Normalize(); } CheckIfOnGround(); horizontalSpeed = baseHorizontalSpeed * speedScale; Vector3 newVelocity = flattenedMovementDirection * horizontalSpeed; newVelocity.y = rigidbody.velocity.y; rigidbody.velocity = newVelocity; if (flattenedMovementDirection != Vector3.zero) { previousHorizontalVector = flattenedMovementDirection; } //currentHorizontalSpeed = Vector3.Scale(rigidbody.velocity, new Vector3(1, 0, 1)).magnitude; //Debug.Log(rigidbody.velocity); if (!isOnGround) { // apply extra gravity. Vector3 additionalGravityForce = (Physics.gravity * gravityMultiplier) - Physics.gravity; rigidbody.AddForce(additionalGravityForce); jumpedThisFrame = false; } else { if (jumpedThisFrame) { jumpedThisFrame = false; rigidbody.velocity = new Vector3(rigidbody.velocity.x, jumpVelocity, rigidbody.velocity.z); if (Jumped != null) { Jumped.Invoke(this); } } } } }
/// <summary> /// Awake the Instance . /// </summary> private void Awake() { //Connect jump. if (jumButton != null) { jumButton.onClick.AddListener(() => { if (Jumped != null) { Jumped.Invoke(); } }); } //Retry. if (retryButton != null) { retryButton.onClick.AddListener(OnResetRequested); //Deactivate at start. retryButton.gameObject.SetActive(false); } }
void playGenome(int genomeIndex) { float dist = getNextNearestCactus().position.x - GetComponent <Rigidbody2D> ().position.x; if (actualJumpGenome >= genomes[genomeIndex].jumps.Count) { } else if (dist <= genomes[genomeIndex].jumps[actualJumpGenome].distanceToNearestCactus.x && isGrounded) { GetComponent <Rigidbody2D> ().velocity = new Vector2(GetComponent <Rigidbody2D> ().velocity.x, jumpHeight); isGrounded = false; Cactus c = getNextNearestCactus(); Jumped jump = new Jumped { nearestCactus = c, distanceToNearestCactus = c.position - GetComponent <Rigidbody2D> ().position }; jumps.Add(jump); actualJumpGenome++; } }
protected void Update() { UpdateGround(); UpdatePlatform(); if (isClient && !isOwner) { UpdateRemote(); return; } character.view.localRotation = Quaternion.AngleAxis(viewPitch, Vector3.left); transform.localRotation = Quaternion.AngleAxis(yaw, Vector3.up); var actualMovement = moveInput.normalized; if (IsOnLadder) { var f = actualMovement.z; actualMovement.z = 0; y = f * 2; } // Apply modifiers var runSpeed = IsSneaking ? settings.SneakSpeed : settings.runSpeed; actualMovement *= runSpeed; if (actualMovement.z <= 0) { actualMovement.z *= settings.backwardSpeedModifier; } actualMovement.x *= settings.sideSpeedModifier; float speedBuff = 1; character.Stats.ModifyStat(CharacterStat.MovementSpeed, ref speedBuff); actualMovement *= speedBuff; if (settings.GainMomentum) { if (IsGrounded) { Momentum = Mathf.Min(Momentum + Time.deltaTime * 0.15f, 1); } if (actualMovement.z < -0.1f || !IsMoving) { Momentum = 0; } var angle = Vector2.Angle(new Vector2(characterController.velocity.x, characterController.velocity.z).normalized, new Vector2(lastVelocity.x, lastVelocity.z).normalized); Momentum *= 1 - Mathf.Clamp01(angle / 180); actualMovement.z *= (1 + Momentum * settings.Momentum); } lastVelocity = characterController.velocity; actualMovement.y = 0; var modifier = IsGrounded ? settings.groundControl : settings.airControl; actualMovement = Vector3.Lerp(lastMovement, actualMovement, modifier); lastMovement = actualMovement; // Landing if (IsGrounded) { if (lastGroundedTime < Time.time - 2) { DeathByLanding?.Invoke(); } if (lastGroundedTime < Time.time - 0.2f) { Momentum *= 0.8f; Landed?.Invoke(); } } // Last grounded if (IsGrounded || IsOnLadder || InProceduralMovement) { lastGroundedTime = Time.time; } // Gravity if (settings.useGravity && !IsOnLadder) { y = Mathf.MoveTowards(y, Physics.gravity.y, Time.deltaTime * 20); } // Jump var wasRecentlyGrounded = lastGroundedTime >= Time.time - settings.JumpGroundedGraceTime; var beginJump = jump && Time.time >= nextJumpTime && wasRecentlyGrounded; if (beginJump) { nextJumpTime = Time.time + settings.JumpCooldown; y = settings.JumpForce; Jumped?.Invoke(); } // Move characterController.Move(transform.rotation * actualMovement * Time.deltaTime + Vector3.up * y * Time.deltaTime); // Consume input moveInput = Vector3.zero; jump = false; if (isClient && Time.time >= nextSendTime) { nextSendTime = Time.time + minSendDelay; RpcServerMove(transform.position, yaw, viewPitch); } }
// Update is called once per frame void Update() { spriteInterval -= Time.deltaTime; if (spriteInterval < 0) { spriteInterval = 0.1f; if (isCrouching) { GetComponent <SpriteRenderer> ().sprite = crouchingSprites [actualSprite]; } else { GetComponent <SpriteRenderer> ().sprite = sprites [actualSprite]; } actualSprite = 1 - actualSprite; } GetComponent <Rigidbody2D> ().velocity = new Vector2(moveSpeed, GetComponent <Rigidbody2D> ().velocity.y); if (isLearning) { if (Input.GetKeyUp(KeyCode.DownArrow)) { isCrouching = false; GetComponent <PolygonCollider2D> ().enabled = true; GetComponent <BoxCollider2D> ().enabled = false; } if (isGrounded && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow))) { isCrouching = false; GetComponent <PolygonCollider2D> ().enabled = true; GetComponent <BoxCollider2D> ().enabled = false; GetComponent <Rigidbody2D> ().velocity = new Vector2(GetComponent <Rigidbody2D> ().velocity.x, jumpHeight); isGrounded = false; Cactus c = getNextNearestCactus(); Jumped jump = new Jumped { nearestCactus = c, distanceToNearestCactus = c.position - GetComponent <Rigidbody2D> ().position }; jumps.Add(jump); } else if (isGrounded && !isCrouching && Input.GetKeyDown(KeyCode.DownArrow)) { isCrouching = true; GetComponent <BoxCollider2D> ().enabled = true; GetComponent <PolygonCollider2D> ().enabled = false; } } else { if (Time.timeScale != 0) { if (Utils.actualGenome < genomes.Count) { playGenome(Utils.actualGenome); } } } }
protected virtual void OnJumped() { Jumped?.Invoke(this, EventArgs.Empty); }
static LocalVehicle() { Screen = new Screen(); HUD = new HUD(); Events.Car.PreExplode.SubscribeAll((sender, data) => { BeforeExploded?.Invoke(null, System.EventArgs.Empty); }); Events.Car.PreSplit.SubscribeAll((sender, data) => { BeforeSplit?.Invoke(null, System.EventArgs.Empty); }); Events.Car.CheckpointHit.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new CheckpointHitEventArgs(data.checkpointIndex_, data.trackT_); CheckpointPassed?.Invoke(null, eventArgs); } }); Events.Car.Death.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new DestroyedEventArgs((DestructionCause)data.causeOfDeath); Destroyed?.Invoke(null, eventArgs); } }); Events.Car.Explode.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new DestroyedEventArgs((DestructionCause)data.causeOfDeath); Exploded?.Invoke(null, eventArgs); } }); Events.RaceEnd.LocalCarHitFinish.Subscribe(data => { BeforeFinished?.Invoke(null, System.EventArgs.Empty); }); Events.Player.Finished.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>() != null) { var eventArgs = new FinishedEventArgs((RaceEndType)data.finishType_, data.finishData_); Finished?.Invoke(null, eventArgs); } }); Events.Car.Horn.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new HonkEventArgs(data.hornPercent_, new Position(data.position_.x, data.position_.y, data.position_.z)); Honked?.Invoke(null, eventArgs); } }); Events.Car.Impact.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new ImpactEventArgs(data.speed_, new Position(data.pos_.x, data.pos_.y, data.pos_.z), data.impactedCollider_.name); Collided?.Invoke(null, eventArgs); } }); Events.Car.Jump.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { Jumped?.Invoke(null, System.EventArgs.Empty); } }); Events.Car.ModeSpecial.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { SpecialModeEvent?.Invoke(null, System.EventArgs.Empty); } }); Events.Player.CarRespawn.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>() != null) { var pos = new Position(data.position_.x, data.position_.y, data.position_.z); var rot = new Rotation(data.rotation_.x, data.rotation_.y, data.rotation_.z); var eventArgs = new RespawnEventArgs(pos, rot, data.fastRespawn_); Respawned?.Invoke(null, eventArgs); } }); Events.Car.Split.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new SplitEventArgs(data.penetration, data.separationSpeed); Split?.Invoke(null, eventArgs); } }); Events.Car.TrickComplete.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { var eventArgs = new TrickCompleteEventArgs(data.cooldownAmount_, data.points_, data.wallRideMeters_, data.ceilingRideMeters_, data.grindMeters_); TrickCompleted?.Invoke(null, eventArgs); } }); Events.Car.WingsStateChange.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { if (data.open_) { WingsOpened?.Invoke(null, System.EventArgs.Empty); } else { WingsClosed?.Invoke(null, System.EventArgs.Empty); } } }); Events.Car.WingsAbilityStateChanged.SubscribeAll((sender, data) => { if (sender.GetComponent <PlayerDataLocal>()) { if (data.enabled_) { WingsEnabled?.Invoke(null, System.EventArgs.Empty); } else { WingsDisabled?.Invoke(null, System.EventArgs.Empty); } } }); }
public void OnPointerDown(PointerEventData eventData) { Jumped?.Invoke(_direction); }
public void Jump(float jumpForce) { rigidbody.AddForce(Vector3.up * 100 * jumpForce); Jumped?.Invoke(); }