public void HandleHit(float n, Color color, Vector2 force) { Unbind(); if (Time.time - lastHit <= 1f) { return; } if (DecreaseBounceHealth(TYRE_IRON_HIT_DAMAGE)) { return; } else { if (Time.time - lastHumanHandling <= 5f) { CreateHitEffect(n, color); BeginTrail(); CachedRigidbody2D.AddForce(force, ForceMode2D.Impulse); StartCoroutine(WaitForZoomIn()); } else { DestroyTrashItem(); return; } lastHit = Time.time; } }
void UpdateMovement() { if (usePhysicsMovement) { /*TrashTransform.up = _lastGroundNormal; * TrashTransform.position = CachedTransform.position; * * Vector2 direction; * * if (currentMovementDirection == MovementDirection.Right) { * direction = TrashTransform.right; * } else { * direction = TrashTransform.right * -1f; * } * * CachedRigidbody2D.AddForce (direction * MovementForce, movementForceMode);*/ CachedRigidbody2D.AddForce(GetDirectionVector() * MovementForce, movementForceMode); //CachedRigidbody2D.AddForceAtPosition (GetDirectionVector () * MovementForce, CachedTransform.position + Vector3.up * 2f, movementForceMode); CachedRigidbody2D.velocity = Vector2.ClampMagnitude(CachedRigidbody2D.velocity, MaxSpeed); } else { Vector3 newPosition = CachedRigidbody2D.position + (GetDirectionVector() * MovementSpeed * Time.fixedDeltaTime); CachedRigidbody2D.MovePosition(newPosition); } }
public void HandleHit(float hitValue, Vector2 swing_Force) { if (IsDead()) { TemporarilyEnableRagdoll(); CachedRigidbody2D.AddForce(swing_Force, ForceMode2D.Impulse); StartCoroutine(WaitForZoomIn()); } }
public void HandleThrow(Vector2 direction, float force, ForceMode2D forceMode) { lastHumanHandling = Time.time; Unbind(); CachedRigidbody2D.AddForce(direction * force, forceMode); AddRandomTorque(); //StartCoroutine (ProcessHandleThrow (direction,force,forceMode)); }
public void Jump() { if (GetState() == HumanState.Jumping) { return; } SetGrounded(false); CachedRigidbody2D.isKinematic = false; Vector2 jumpVector = Vector2.up * jumpForce; if (usePhysicsMovement) { Vector2 velocity = CachedRigidbody2D.velocity; velocity = Vector2.ClampMagnitude(velocity, MaxSpeed); if (IsMoving()) { //jumpVector = (Vector2.up + GetDirectionVector ()).normalized; jumpVector = (Vector2.up + GetDirectionVector() * 0.5f); } else { jumpVector = Vector2.up; } jumpVector *= jumpForce; } else { Vector2 movementDirection = GetDirectionVector(); float movementSpeed = MovementSpeed; jumpVector += movementDirection * movementSpeed; } EndMovement(); humanState.SetState(HumanState.Jumping); CachedRigidbody2D.AddForce(jumpVector, ForceMode2D.Impulse); StartCoroutine(WaitForJump()); }
public void HandleHitByItem(TrashItem trashItem) { Vector2 velocity = trashItem.CachedRigidbody2D.velocity; if (velocity.magnitude >= killVelocity) { velocity *= killVelocityMultiplier; velocity += Vector2.up * killUpwardVelocity; SetState(HumanState.Dying); CachedRigidbody2D.AddTorque(UnityEngine.Random.Range(killTorqueRange.x, killTorqueRange.y), ForceMode2D.Impulse); } CachedRigidbody2D.AddForce(velocity, ForceMode2D.Impulse); }
void EnableDeathColliders() { CachedAnimator.enabled = false; //CachedRigidbody2D.isKinematic = true; CachedRigidbody2D.AddForce(Vector2.up * 10f); SetColliders(livingColliders, null, false); SetColliders(deathColliders, deathRigidbodies, true); for (int i = 0; i < deathJoints.Length; i++) { deathJoints [i].enabled = true; deathJoints [i].gameObject.GetComponent <Rigidbody2D> ().isKinematic = true; } }
public void AddRandomTorque() { CachedRigidbody2D.AddTorque(UnityEngine.Random.Range(-RANDOM_TORQUE_AMOUNT, RANDOM_TORQUE_AMOUNT)); }
public void HandleHitByPlayer(Vector2 force) { CachedRigidbody2D.AddForce(force, ForceMode2D.Impulse); SetGrounded(false); }