public void Calculate(MyRigidbody body1, MyRigidbody body2, Vector3 collNormalWorld1To2, Vector3 collPointWorld) { var v1 = body1.VelocityWorldAtPoint(collPointWorld); var v2 = body2.VelocityWorldAtPoint(collPointWorld); var vr = v2 - v1; var signedImpact = Vector3.Dot(vr, collNormalWorld1To2); if (signedImpact < 0.0f) { var r1 = body1.transform.InverseTransformPoint(collPointWorld); var r2 = body2.transform.InverseTransformPoint(collPointWorld); var collisionNormalBody1Local = body1.transform.InverseTransformDirection(collNormalWorld1To2); var collisionNormalBody2Local = body2.transform.InverseTransformDirection(collNormalWorld1To2); var s1 = CalculateS(collisionNormalBody1Local, r1, body1); var s2 = CalculateS(collisionNormalBody2Local, r2, body2); var m1 = body1.Mass; var m2 = body2.Mass; var J = (-signedImpact * (e + 1.0f)) / (1.0f / m1 + 1.0f / m2 + s1 + s2); var impact = -signedImpact; Body1Impulse.Set(-J * collNormalWorld1To2, -J * collisionNormalBody1Local, collPointWorld, r1, impact); Body2Impulse.Set(J * collNormalWorld1To2, J * collisionNormalBody2Local, collPointWorld, r2, impact); body1.SetImpulse(Body1Impulse); body2.SetImpulse(Body2Impulse); } }
private void HandleMovement(float inputX) { if (MyRigidbody.velocity.y < -0.01f) { MyAnimator.SetBool("land", true); } if (actState.Equals(ActState.StandBy) && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(inputX * (base.stat.Spd.CurrentVal + runSpd), MyRigidbody.velocity.y); } if (Jump && Mathf.Abs(MyRigidbody.velocity.y) < 0.01f) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } if (Input.GetKey(KeyCode.LeftShift)) { runSpd = 2; } else { runSpd = 0; } MyAnimator.SetFloat("speed", Mathf.Abs(inputX)); }
//handles movement private void HandleMovement(float horizontal) { //if allows for diagonal spring to work need to tweak how movement works if vertical springs are to work //if(airControl) MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); myAnimator.SetFloat("speed", Mathf.Abs(horizontal)); //handles Running if (running) { myAnimator.SetBool("run", true); } else if (!running) { myAnimator.SetBool("run", false); } //jumping if (jump && isGrounded) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } myAnimator.SetFloat("ySpeed", MyRigidbody.velocity.y); //calls flip after movement is decided Flip(horizontal); }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0 && !OnGround) { MyAnimator.SetBool("falling", true); MyAnimator.SetBool("jump bool", false); } if (MyRigidbody.velocity.y == 0 && Time.time - jumpTime > 0.10) { MyAnimator.SetBool("jump bool", false); } if (!MyAnimator.GetBool("slide") && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (OnGround && Jump) { OnGround = false; MyRigidbody.AddForce(new Vector2(0, jumpForce)); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == "Springy") { MyRigidbody.AddForce(new Vector2(0, 800)); } }
private void FixedUpdate() { if (Follow) { MyRigidbody.FollowTargetWithRotation(MyPlayer.PlayerTargetting.EnemyTransform, _myBulletSettings.DistanceToStop, _myBulletSettings.Speed); } }
IEnumerator KnockBack() { MyRigidbody.AddForce(-transform.right * 300 * Time.deltaTime, ForceMode2D.Impulse); yield return(new WaitForSeconds(0.2f)); MyRigidbody.velocity = Vector2.zero; }
private void HandleMovement(float horizontal, float vertical) { if (isRunning) { movementSpeed = 5f; } else { movementSpeed = 2f; } if (IsFalling) { gameObject.layer = 11; MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } if (OnLadder) { MyAnimator.speed = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal); MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Input.GetKeyDown(KeyCode.UpArrow) && !OnGround && canDoubleJump) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); canDoubleJump = false; } else if (Input.GetKeyDown(KeyCode.UpArrow) && OnGround) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); canDoubleJump = true; } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); // Seteaza parametrul speed al animatorului in 1 --> se activeaza animatia run }
private void HandleMovement(float horizontal) // so we can use it here to change the value so defined earlier { if (MyRigidbody.velocity.y < 0) { myAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl))// && (KnockBackCount <= 0)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); //moveVelocity = movementSpeed; } //else //{ // if (KnockFromRight) // MyRigidbody.velocity = new Vector2(-KnockBack, KnockBack); //if (!KnockFromRight) // MyRigidbody.velocity = new Vector2(KnockBack, KnockBack); // KnockBackCount -= Time.deltaTime; //} //MyRigidbody.velocity = new Vector2(moveVelocity, MyRigidbody.velocity.y); if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } myAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && !Crouch || (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0 && !Crouch) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } ////player boundaries on X axis //if (transform.position.x <= -4.3f) //{ // transform.position = new Vector2(-4.3f, transform.position.y); //} //else if (transform.position.x >= 27.75f) //{ // transform.position = new Vector2(27.75f, transform.position.y); //} MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
public MyContactPoint(Vector3 point, Vector3 normal, float distance, MyRigidbody _this, MyRigidbody _other) { Point = point; Normal = normal; Distance = distance; This = _this; Other = _other; }
public IEnumerator CloseDistance(Vector2 direction, float speed, float time) { MyRigidbody.AddForce(direction.normalized * speed * Time.deltaTime, ForceMode2D.Impulse); MyAnimator.enabled = false; yield return(new WaitForSeconds(time)); MyAnimator.enabled = true; MyRigidbody.velocity = Vector2.zero; }
void OnCollisionEnter2D(Collision2D other) { float xDir = transform.position.x - other.transform.position.x; if (other.gameObject.tag == "Demons") { MyRigidbody.AddForce(new Vector2(knockBack * xDir, 0)); StartCoroutine(TakeDamage()); } }
private void HandleDash() { if (isDashDownButton) { MyRigidbody.collisionDetectionMode = CollisionDetectionMode2D.Continuous; MyRigidbody.MovePosition(transform.position + CheckMouseDir(direction) * dashDistance); isDashDownButton = false; } }
public void RemoveRigidbody(MyRigidbody _rigid) { if (_rigid == null) { return; } if (m_toRemove.Contains(_rigid)) { return; } m_toRemove.Add(_rigid); }
private void HandleInput() { if (Input.GetKeyDown(KeyCode.DownArrow)) { MyAnimator.SetBool("crouch", true); } if (Input.GetKeyUp(KeyCode.DownArrow)) { MyAnimator.SetBool("crouch", false); } if (Input.GetKeyDown(KeyCode.UpArrow)) { MyAnimator.SetTrigger("jump"); if (Jump && !OnGround) { if (Input.GetKeyDown(KeyCode.UpArrow)) { MyRigidbody.AddForce(new Vector2(0, doubleJumpForce)); MyAnimator.SetTrigger("jump"); } } } if (Input.GetKeyDown(KeyCode.LeftShift)) { MyAnimator.SetTrigger("slide"); } if (Input.GetKeyDown(KeyCode.LeftControl)) { MyAnimator.SetTrigger("attack"); } if (Input.GetKeyDown(KeyCode.V)) { MyAnimator.SetTrigger("throw"); MyAnimator.SetBool("carry", false); } if (Input.GetKeyDown(KeyCode.R)) { MyAnimator.SetTrigger("invoke"); InvokeDoberman(0); } if (Input.GetKeyDown(KeyCode.Escape)) { SceneManager.LoadScene("Menu"); } }
public void BtnJump() { // Used for button to make player jump if (OnGround && !IsDead) { MyAnimator.SetTrigger("jump"); MyRigidbody.AddForce(new Vector2(0, jumpForce)); Jump = true; } }
public void AddRigidbody(MyRigidbody _rigid) { if (_rigid == null) { return; } if (m_activeRigidbodies.Contains(_rigid)) { return; } m_activeRigidbodies.Add(_rigid); }
private void AttackCharge() { if (transform.localScale.x > 0) { Vector2 KnuckBackVelocity = new Vector2(12.5f, 0); MyRigidbody.AddForce(KnuckBackVelocity, ForceMode2D.Impulse); } else if (transform.localScale.x < 0) { Vector2 KnuckBackVelocity = new Vector2(-12.5f, 0); MyRigidbody.AddForce(KnuckBackVelocity, ForceMode2D.Impulse); } }
private void handleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { myAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } myAnimator.SetFloat("speed", Mathf.Abs(horizontal)); /*if (myRigidbody.velocity.y < 0) { * * myAnimator.SetBool ("land", true); * } * * if (!myAnimator.GetBool("slide") && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack") && (isGrounded || airControl)) { * * //myRigidbody.velocity = Vector2.left; // x=-1, y=0 * myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y); * * } * * if (isGrounded && jump) { * * isGrounded = false; * myRigidbody.AddForce (new Vector2 (0, jumpForce)); * myAnimator.SetTrigger ("jump"); * } * * if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide")) { * * myAnimator.SetBool ("slide", true); * } * * else if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide")) * { * * myAnimator.SetBool ("slide", false); * } * * myAnimator.SetFloat ("speed", Mathf.Abs(horizontal));*/ }
private void HandleMovement(float horizontal, float vertical) { if (Falling) { gameObject.layer = 10; MyAnimator.SetBool("land", true); } if (Jump && OnGround /*MyRigidbody.velocity.y == 0*/ && !OnLadder) { Debug.Log("-----------in side jumpmp OnGround--------------" + OnGround); MyRigidbody.AddForce(new Vector2(0, jumpForce)); //MyRigidbody.velocity = (new Vector2(Mathf.Lerp(btnHorizontal, horizontal, Time.fixedDeltaTime * 2), jumpForce)); //Player.Instance.transform.position += new Vector3(Player.Instance.horizontal == 1 ? 1 : -1, 0.5f, 0) * Time.fixedDeltaTime * 100; Jump = false; } if (!Attack && !Slide && (OnGround || airControl)) { //Debug.Log("-----------in side run--------------" + Mathf.Lerp(btnHorizontal, horizontal, Time.fixedDeltaTime * 2)); MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } //Debug.Log("-----------Jump--------------" + Jump/*+ "MyRigidbody.velocity.y == "+ MyRigidbody.velocity.y*/); //Debug.Log("-----------OnGround--------------" + OnGround); rd_velocity_x = MyRigidbody.velocity.x; rd_velocity_y = MyRigidbody.velocity.y; if (OnLadder) { MyAnimator.speed = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal); MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); Flip(horizontal); if (directionChanged) { directionChanged = false; touchThrow = false; } else { if (touchThrow) { MyAnimator.SetTrigger("throw"); touchThrow = false; } } }
private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
// handles the movement of the player. private void HandleMovement(float horizontal) { if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); // if the player is traveling down plays the land aniamtion. } if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); //moves the player. } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); // applies force so the player can jump. } MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); // sets the animator to play the run animation. }
public void Knockback(float KnockBackLength) // 넉백 거리 { MyRigidbody.velocity = Vector2.zero; Vector2 KnuckBackVelocity_Right = new Vector2(KnockBackLength, MyRigidbody.velocity.y); Vector2 KnuckBackVelocity_Left = new Vector2(-KnockBackLength, MyRigidbody.velocity.y); // 오른쪽 if (transform.position.x > Player.position.x) { MyRigidbody.AddForce(KnuckBackVelocity_Right, ForceMode2D.Impulse); } // 왼쪽 else { MyRigidbody.AddForce(KnuckBackVelocity_Left, ForceMode2D.Impulse); } }
private void HandleMovement(float horizontal) { if (IsFalling && OnGround) { myAnimator.SetBool("land", true); } if (!Attack && (OnGround || airControl) && !knockBack) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if ((Jump && (MyRigidbody.velocity.y == 0) && OnGround)) { myAnimator.SetBool("land", false); MyRigidbody.AddForce(new Vector2(0, (MyRigidbody.velocity.y * 0) + jumpforce)); } myAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }
private void FixedUpdate() { if (IsSpore) { IsSubdivided = true; if (!drifting) { MyConstantForce.enabled = false; MyConstantForce.force = new Vector2(); MyRigidbody.velocity = (MyRigidbody.velocity * (1f - (Time.fixedDeltaTime * 2f))); if (MyRigidbody.velocity.magnitude < 0.1f) { driftTime = Time.time; drifting = true; } } else { MyConstantForce.enabled = true; MyConstantForce.force = Vector2.Lerp(MyConstantForce.force, (Random.insideUnitCircle.normalized * (WINDFORCEFACTOR * .2f * (1f + (Astronaut.AggressionLevelF * 1f)))), .5f) + ((new Vector2(0f, -1f) * .25f) * (1f - Astronaut.AggressionLevelF)); if ((Time.time - driftTime) >= 15f) { explode(); } } } else { if (Live) { if (IsSubdivided) { MyConstantForce.force = Vector2.Lerp(MyConstantForce.force, (Random.insideUnitCircle.normalized * WINDFORCEFACTOR), 1f); } Astronaut plr = Astronaut.TheAstronaut; Vector3 dif = (plr.transform.position - this.transform.position); if (dif.magnitude < 8f) { //nerfed. They came from nowhere at full speed and you had no time to react. MyRigidbody.AddForce(new Vector2(dif.x, dif.y).normalized *WINDFORCEFACTOR * 1f * Astronaut.AggressionLevelF); } } } }
//METHODS: private void HandleMovement(float horizontal) // The horizontal in the parenthesis gets its value from the float Horizontal = blah blah in the fixed update { if (!Attack && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(horizontal * movementSpeed, jumpForce)); } MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal)); if (Crouch) { MyRigidbody.velocity = new Vector2(0, MyRigidbody.velocity.y); } }
private void HandleMovement(float horizontal) { if (Jumping && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } if (IsFalling) { gameObject.layer = 10; MyAnimator.SetBool("Land", true); } if (!Attacking && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); } MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal)); }
// This is a function for player movement private void HandleMovement(float horizontal) { // If we are falling then start the landing animation if (MyRigidbody.velocity.y < 0) { MyAnimator.SetBool("land", true); } // Horizontal movement if (!Attack && !Slide && (OnGround || airControl)) { MyRigidbody.velocity = new Vector2(movementSpeed * horizontal, MyRigidbody.velocity.y); } if (Jump && MyRigidbody.velocity.y == 0) { MyRigidbody.AddForce(new Vector2(0, jumpForce)); } // Set the speed in the Animator MyAnimator.SetFloat("speed", Mathf.Abs(horizontal)); }