void Update() { // 上下移动。并到达位置后,开始计时。计时结束后往反方向移动。 if (TimeController.Instance.IsOpTime()) { return; } if (Up) { if (KeepTime > 0f) { Rigid.AddForce(new Vector2(0f, 2000f * MoveSpeed)); KeepTime -= Time.deltaTime; } } else { // 移动部分 if (KeepTime > 0f) { KeepTime -= Time.deltaTime; } else { Rigid.AddForce(new Vector2(0f, 2000f * MoveSpeed)); } } }
private IEnumerator Assault() { IsAttack = true; IsChase = false; yield return(new WaitForSeconds(0.3f)); Ani.SetBool("isAttack", true); yield return(new WaitForSeconds(0.2f)); AttackObject attack = GameManager.Instance.Pooling.GetAttackObject(PoolManager.AttackObjectList.MonsterMeleeAttack); attack.transform.SetParent(transform); attack.transform.localPosition = Vector3.zero; attack.transform.rotation = transform.rotation; var attackInfo = new AttackInfo(this, Atk * AssaultDamage, 10f, "Player", transform.position, int.MaxValue, (HitInfo info) => { GameManager.Instance.Effect.HitEffect(info.HitUnit.transform.position); }); attack.SetAttackInfo(attackInfo, AttackObject.IgnoreType.IgnoreWallAndFloor); attack.SetTimer(1f, InstantObject.TimerAction.Destory); Rigid.AddForce(transform.forward * AssaultForce, ForceMode.Impulse); yield return(new WaitForSeconds(1f)); Rigid.velocity = Vector3.zero; yield return(new WaitForSeconds(0.8f)); //공격 후딜레이 yield return(new WaitForSeconds(0.25f)); Ani.SetBool("isAttack", false); IsAttack = false; IsChase = true; }
public void TwoBodysWithSpringPushAway() { World w = new World (); Rigid r1 = new Rigid (30, new Matrix (70, 70, 70)); r1.StartCenterOfMass = new Vector (); w.AddRigid (r1); w.AddEffect (new Force (new Vector (-30, 0, 0), r1)); Rigid r2 = new Rigid (30, new Matrix (70, 70, 70)); r2.StartCenterOfMass = new Vector (10, 0, 0); w.AddRigid (r2); w.AddEffect (new Force (new Vector (30, 0, 0), r2)); Vector v = new Vector (); Spring spring = new Spring (r1, v, r2, v, 300, 0); w.AddEffect (spring); State s1 = new State (w); s1.Simulate (5); Assert.AreEqual (-0.0966, s1.RigidStates [r1].CenterOfMass.X, 0.001); Assert.AreEqual (0.0808, s1.RigidStates [r1].LinearVelocity.X, 0.001); Assert.AreEqual (0.9324, s1.RigidStates [r1].LinearAcceleration.X, 0.001); Assert.AreEqual (10.0966, s1.RigidStates [r2].CenterOfMass.X, 0.001); Assert.AreEqual (-0.0808, s1.RigidStates [r2].LinearVelocity.X, 0.001); Assert.AreEqual (-0.9324, s1.RigidStates [r2].LinearAcceleration.X, 0.001); }
public void InitializeCharacter(CharacterIdentity ci) { characterIdentity = ci; trans = model.GetComponent <Transform>(); rigid = GetComponent <Rigid>(); mState = new IdleState(); mDelayState = new IdleDelayState(); gameSystemState = SystemOrder.NOTHING; inputOrder = InputOrder.stand; attackOrder = -1; walkDirection = new Vector3(0, 0, 0); sightRotation = new Vector3(0, 0, 0); posture = new Posture(this); walkPhase = 0; attackPhase = 0; holdingItemIndex = -1; if (characterIdentity.isPlayer) { GetComponent <Basic>().mManager.allManager.SetCamera(gameObject); posture.BecomeInvisible(); targetCharacter = null; } else { targetCharacter = GetComponent <Basic>().mManager.allManager.player; } }
public void TwoBodysWithDamperPullTogether() { World w = new World (); Rigid r1 = new Rigid (30, new Matrix (70, 70, 70)); r1.StartCenterOfMass = new Vector (); w.AddRigid (r1); w.AddEffect (new Force (new Vector (30, 0, 0), r1)); Rigid r2 = new Rigid (30, new Matrix (70, 70, 70)); r2.StartCenterOfMass = new Vector (10, 0, 0); w.AddRigid (r2); w.AddEffect (new Force (new Vector (-30, 0, 0), r2)); Vector v = new Vector (); Damper damper = new Damper (r1, v, r2, v, 30); w.AddEffect (damper); State s1 = new State (w); s1.Simulate (5); Assert.AreEqual (2.25, s1.RigidStates [r1].CenterOfMass.X, 0.001); Assert.AreEqual (0.5, s1.RigidStates [r1].LinearVelocity.X, 0.001); Assert.AreEqual (0.0, s1.RigidStates [r1].LinearAcceleration.X, 0.001); Assert.AreEqual (7.75, s1.RigidStates [r2].CenterOfMass.X, 0.001); Assert.AreEqual (-0.5, s1.RigidStates [r2].LinearVelocity.X, 0.001); Assert.AreEqual (0.0, s1.RigidStates [r2].LinearAcceleration.X, 0.001); }
public override void Movement() { var dir = (ActivePlayer.Trans.position - Trans.position).normalized; dir = dir.normalized * MovementSpeed * Time.deltaTime; Rigid.MovePosition(Trans.position + dir); }
public void InitializeItemMarker(int id) { itemID = id; owner = null; rigid = GetComponent <Rigid>(); protectTime = 1.0f; }
protected virtual void FixedUpdate() { if (_hasRotated) { Rigid.MoveRotation(_targetRotation); _hasRotated = false; } }
public void Jump() { if (isGrounded && minJumpTime <= 0f) { Rigid.AddForce(Vector2.up * JumpForce); minJumpTime = 1f; } }
public override void Progress() { Rigid.MovePosition(Vector3.MoveTowards(transform.position, transform.position + speed * Direction, inversedMoveTime * Time.deltaTime)); lifeSpan--; if (lifeSpan < 0 || (k514SystemManager.InteractMgr.GetPlayerVector().z - transform.position.z) > 2f) { Interactive_Destroy(); } }
public void NewRigidStateTest() { Rigid r = new Rigid (1, new Matrix (1, 1, 1)); RigidState rs = new RigidState (r); Assert.AreEqual (0, rs.CenterOfMass.X); Assert.AreEqual (0, rs.CenterOfMass.Y); Assert.AreEqual (0, rs.CenterOfMass.Z); }
public override void Hurt(ActorInstance actor, int damage = 0, int currentHP = 0, string cause = "attack", bool crit = false) { base.Hurt(actor, damage, currentHP, cause, crit); if (Game.Instance.isBitch) { Rigid.AddForce(2f * actor.Info.ClientPerks.KnockbackModifier * transform.position - actor.transform.position, ForceMode2D.Impulse); } }
public override void OnRelease() { base.OnRelease(); Picked = false; Rigid.isKinematic = false; Rigid.useGravity = true; Rigid.AddForce(Camera.main.transform.forward * throwForce); }
public void SimulateMovementTest() { Rigid r = new Rigid (1, new Matrix (1, 1, 1)); RigidState rs = new RigidState (r); rs.LinearAcceleration = new Vector (1, 0, 0); rs.SimulateMovement (1, new Euler ()); Assert.AreEqual (1, rs.CenterOfMass.X, 0.01); Assert.AreEqual (0, rs.CenterOfMass.Y, 0.01); Assert.AreEqual (0, rs.CenterOfMass.Z, 0.01); }
protected override void Move() { Vector2 dir = Value.JoyTouch; MoveDirc = dir; float TileSpeed = OnTile.TileSpeed; Vector2 Movedir = (dir * TileSpeed * Speed * Time.deltaTime); //transform.position = new Vector2(transform.position.x + dir.x, transform.position.y + dir.y); Rigid.MovePosition(Rigid.position + Movedir); Render.sortingOrder = -(int)Rigid.position.y; }
public void LinearBasicTest() { World w = new World (); Rigid r = new Rigid (10, new Matrix (1, 1, 1)); w.AddRigid (r); w.AddEffect (new Force (new Vector (1, 0, 0), r)); State s = new State (w, 0.001); s.Simulate (2); Assert.AreEqual (0.1, s.RigidStates [r].LinearAcceleration.X, 0.001); Assert.AreEqual (0.2, s.RigidStates [r].LinearVelocity.X, 0.001); Assert.AreEqual (0.2, s.RigidStates [r].CenterOfMass.X, 0.001); }
//bool CheckGround() //{ // Collider2D collider = Physics2D.OverlapCircle(transform.position + Offset, // Radius, GroundLayer); // return collider != null ? true : false; // //if(collider != null) // //{ // // return true; // //} // //else // //{ // // return false; // //} //} void Jump() { if (!groundChecker.IsGround) // isGround == false; { return; } if (Input.GetKeyDown(KeyCode.Space)) { Rigid.AddForce(Vector3.up * JumpForce, ForceMode2D.Impulse); } }
void Jump() { if (!isGround) { return; } if (Input.GetKeyDown(KeyCode.Space)) { Rigid.AddForce(Vector3.up * JumpForce, ForceMode2D.Impulse); } }
private void FixedUpdate() { if (_ragdoll.ReferenceSystem != null) { Rigid.MovePosition(_ragdoll.ReferenceSystem.ProjectOnPlane(Rigid.position)); } //if (Rigid.velocity.sqrMagnitude < Ragdoll.GroundParams.StopVelocityMaxSqr) // IsGrounded = (_groundTimer -= Time.fixedDeltaTime) < 0f; //else // _groundTimer = Ragdoll.GroundParams.Timeout; }
public override void Movement() { var x = CanMoveX ? Input.GetAxisRaw("Horizontal") : 0; var z = CanMoveZ ? Input.GetAxisRaw("Vertical") : 0; var input = new Vector3(x, 0, z); input = input.normalized * MovementSpeed * Time.deltaTime; Rigid.MovePosition(Trans.position + input); if (CanJump && Input.GetKeyDown(KeyCode.Space) && FloorPlane.GetDistanceToPoint(Trans.position) < 0.51f) { Rigid.AddForce(Vector3.up * 6, ForceMode.Impulse); } }
public void LinearBasicStepTest() { World w = new World (); Rigid r = new Rigid (10, new Matrix (1, 1, 1)); w.AddRigid (r); w.AddEffect (new Force (new Vector (1, 0, 0), r)); State s = new State (w, 0.001); s.InitState (); s.ForwardStep (); Assert.AreEqual (10, s.RigidStates [r].Mass, 0.0001); Assert.AreEqual (1, s.RigidStates [r].StateForceList.Force.X, 0.001); Assert.AreEqual (0.1, s.RigidStates [r].LinearAcceleration.X, 0.001); }
/// <summary> /// Handling the jump and the airborne movement if the player is airborne /// </summary> private void HandleJump() { if (IsGrounded) { if (CTRLHub.inst.JumpDown && IsFrozen == false) { Rigid.AddForce(-normalizedGravity * maxJumpforce, ForceMode.Impulse); airebornMovementDirection = movementDirection; } } else { Rigid.AddForce(airebornMovementDirection * jumpForwardStrength); airebornMovementDirection = Vector3.Lerp(airebornMovementDirection, Vector3.zero, dropMovementForceWeakening * Time.deltaTime); } }
public override void Hurt(ActorInstance actor, int damage = 0, int currentHP = 0, string cause = "attack", bool crit = false) { base.Hurt(actor, damage, currentHP, cause, crit); if (Game.Instance.isBitch) { if (actor.transform.position.x < transform.position.x) { Rigid.gravityScale = 1f; Rigid.AddForce((damage / Info.MaxHealth) * 3f * actor.Info.ClientPerks.KnockbackModifier * transform.right, ForceMode2D.Impulse); } else { Rigid.gravityScale = 1f; Rigid.AddForce((damage / Info.MaxHealth) * 3f * actor.Info.ClientPerks.KnockbackModifier * -transform.right, ForceMode2D.Impulse); } } }
public override void Movement() { if (_isChargeing) { _chargePercentage += Time.deltaTime * 20; if (_chargePercentage >= 100) { _isChargeing = false; Rigid.AddForce(Trans.forward * 30, ForceMode.Impulse); } Trans.LookAt(ActivePlayer.Trans); } else { _chargePercentage -= Time.deltaTime * 20; if (_chargePercentage <= 0) { _isChargeing = true; } } }
/// <summary> /// Adds the <see cref="Rigid"/>. /// </summary> /// <param name='r'> /// This <see cref="Rigid"/> will be added to the world. /// </param> public void AddRigid(Rigid r) { Rigids.Add (r); }
public void OneWorldTwoStatesTest() { World w = new World (); Rigid r1 = new Rigid (30, new Matrix (70, 70, 70)); w.AddRigid (r1); w.AddEffect (new Force (new Vector (30, 0, 0), r1, new Vector (5, 0, 0))); w.AddEffect (new Moment (new Vector (0, 0, 50), r1)); Rigid r2 = new Rigid (5, new Matrix (200, 200, 200)); r2.StartCenterOfMass = new Vector (10, 10, 10); w.AddRigid (r2); w.AddEffect (new Force (new Vector (10, 0, 0), r2, new Vector (0, -100, 0))); State s1 = new State (w, 0.0001); State s2 = new State (w, 0.001); s1.Simulate (1); s2.Simulate (2); s1.ForwardStep (); Assert.AreEqual (0, s1.RigidStates [r1].LinearAcceleration.Y, 0.1); Assert.AreEqual (0, s1.RigidStates [r1].LinearVelocity.Y, 0.1); Assert.AreEqual (0, s1.RigidStates [r1].CenterOfMass.Y, 0.1); Assert.AreEqual (1, s1.RigidStates [r1].LinearAcceleration.X, 0.1); Assert.AreEqual (1, s1.RigidStates [r1].LinearVelocity.X, 0.1); Assert.AreEqual (0.5, s1.RigidStates [r1].CenterOfMass.X, 0.1); Assert.AreEqual (0.71, s1.RigidStates [r1].AngularAcceleration.Z, 0.1); Assert.AreEqual (0.71, s1.RigidStates [r1].AngularVelocity.Z, 0.1); Assert.AreEqual (0.36, s1.RigidStates [r1].AnglesOfRotation.Z, 0.1); Assert.AreEqual (0, s1.RigidStates [r2].LinearAcceleration.Y, 0.1); Assert.AreEqual (0, s1.RigidStates [r2].LinearVelocity.Y, 0.1); Assert.AreEqual (10, s1.RigidStates [r2].CenterOfMass.Y, 0.1); Assert.AreEqual (2, s1.RigidStates [r2].LinearAcceleration.X, 0.1); Assert.AreEqual (2, s1.RigidStates [r2].LinearVelocity.X, 0.1); Assert.AreEqual (11, s1.RigidStates [r2].CenterOfMass.X, 0.1); Assert.AreEqual (10, s1.RigidStates [r2].CenterOfMass.Z, 0.1); Assert.AreEqual (5, s1.RigidStates [r2].AngularAcceleration.Z, 0.1); Assert.AreEqual (5, s1.RigidStates [r2].AngularVelocity.Z, 0.1); Assert.AreEqual (2.5, s1.RigidStates [r2].AnglesOfRotation.Z, 0.1); Assert.AreEqual (0, s2.RigidStates [r1].LinearAcceleration.Y, 0.1); Assert.AreEqual (0, s2.RigidStates [r1].LinearVelocity.Y, 0.1); Assert.AreEqual (0, s2.RigidStates [r1].CenterOfMass.Y, 0.1); Assert.AreEqual (1, s2.RigidStates [r1].LinearAcceleration.X, 0.1); Assert.AreEqual (2, s2.RigidStates [r1].LinearVelocity.X, 0.1); Assert.AreEqual (2, s2.RigidStates [r1].CenterOfMass.X, 0.1); Assert.AreEqual (0.71, s2.RigidStates [r1].AngularAcceleration.Z, 0.1); Assert.AreEqual (1.43, s2.RigidStates [r1].AngularVelocity.Z, 0.1); Assert.AreEqual (1.43, s2.RigidStates [r1].AnglesOfRotation.Z, 0.1); Assert.AreEqual (0, s2.RigidStates [r2].LinearAcceleration.Y, 0.1); Assert.AreEqual (0, s2.RigidStates [r2].LinearVelocity.Y, 0.1); Assert.AreEqual (10, s2.RigidStates [r2].CenterOfMass.Y, 0.1); Assert.AreEqual (2, s2.RigidStates [r2].LinearAcceleration.X, 0.1); Assert.AreEqual (4, s2.RigidStates [r2].LinearVelocity.X, 0.1); Assert.AreEqual (14, s2.RigidStates [r2].CenterOfMass.X, 0.1); Assert.AreEqual (10, s2.RigidStates [r2].CenterOfMass.Z, 0.1); Assert.AreEqual (5, s2.RigidStates [r2].AngularAcceleration.Z, 0.1); Assert.AreEqual (10, s2.RigidStates [r2].AngularVelocity.Z, 0.1); Assert.AreEqual (10, s2.RigidStates [r2].AnglesOfRotation.Z, 0.1); }
public void NonCentricMomentTest() { World w = new World (); Rigid r = new Rigid (5, new Matrix (5, 5, 5)); w.AddRigid (r); w.AddEffect (new Moment (new Vector (0, 0, 10), r, new Vector (0.5, 0, 0))); State s = new State (w, 0.001); s.Simulate (3); Assert.AreEqual (4, s.RigidStates [r].LinearAcceleration.Y, 0.1); Assert.AreEqual (12, s.RigidStates [r].LinearVelocity.Y, 0.1); Assert.AreEqual (18, s.RigidStates [r].CenterOfMass.Y, 0.1); Assert.AreEqual (2, s.RigidStates [r].AngularAcceleration.Z, 0.1); Assert.AreEqual (6, s.RigidStates [r].AngularVelocity.Z, 0.1); Assert.AreEqual (9, s.RigidStates [r].AnglesOfRotation.Z, 0.1); }
public void AngularBasicTest() { World w = new World (); Rigid r = new Rigid (23, new Matrix (5, 5, 5)); w.AddRigid (r); w.AddEffect (new Moment (new Vector (2, 0, 0), r)); State s = new State (w, 0.001); s.Simulate (2); Assert.AreEqual (0.4, s.RigidStates [r].AngularAcceleration.X, 0.001); Assert.AreEqual (0.8, s.RigidStates [r].AngularVelocity.X, 0.001); Assert.AreEqual (0.8, s.RigidStates [r].AnglesOfRotation.X, 0.01); }
public void TwoBodyGravityTest() { World w = new World (); w.AddEffect (new Gravity ()); Rigid r1 = new Rigid (10, new Matrix (1, 1, 1)); w.AddRigid (r1); Rigid r2 = new Rigid (20, new Matrix (1, 1, 1)); w.AddRigid (r2); State s = new State (w, 0.001); s.Simulate (2.5); Assert.AreEqual (-9.81, s.RigidStates [r1].LinearAcceleration.Y, 0.01); Assert.AreEqual (-24.52, s.RigidStates [r1].LinearVelocity.Y, 0.02); Assert.AreEqual (-30.65, s.RigidStates [r1].CenterOfMass.Y, 0.1); Assert.AreEqual (-9.81, s.RigidStates [r2].LinearAcceleration.Y, 0.01); Assert.AreEqual (-24.52, s.RigidStates [r2].LinearVelocity.Y, 0.02); Assert.AreEqual (-30.65, s.RigidStates [r2].CenterOfMass.Y, 0.1); }
/// <summary> /// Applies AddForce in 'movementDirection' using the given strength and ForceMode, /// according to the inputed movement strength ('GetInputMagnitude()') /// </summary> private void ApplyForceInMovementDirection(float strength, ForceMode forceMode = ForceMode.Force) { Rigid.AddForce(movementDirection * strength * GetInputMagnitude(), forceMode); }
public void RevisarPegados(float filtroOverlap = 0f) { pegados.Clear(); pegadosRigid.Clear(); pegadosColliders.Clear(); pegadosFiltrados.Clear(); pegadosTocandoPoco.Clear(); arriba.Clear(); abajo.Clear(); derecha.Clear(); izquierda.Clear(); if (Rigid) { var contactos = new ContactPoint2D[50]; int cant = Rigid.GetContacts(contactos); for (int i = 0; i < cant; i++) { var contacto = contactos[i]; var tuBoxCol = contacto.collider as BoxCollider2D; var miBox = BoxCol ? BoxCol : contacto.otherCollider as BoxCollider2D; if (tuBoxCol && !pegadosColliders.Contains(tuBoxCol)) { pegadosColliders.Add(tuBoxCol); var tuBoundsMax = tuBoxCol.bounds.max; var tuBoundsMin = tuBoxCol.bounds.min; var miBoundsMax = miBox.bounds.max; var miBoundsMin = miBox.bounds.min; // Nueva tecnica, se tomaran los bloques incluyendo superposiciones, un mismo bloque que esta arriba y abajo entra en ambos grupos if (tuBoundsMax.y > miBoundsMax.y) { arriba.Add(tuBoxCol); } if (tuBoundsMin.y < miBoundsMin.y) { abajo.Add(tuBoxCol); } if (tuBoundsMax.x > miBoundsMax.x) { derecha.Add(tuBoxCol); } if (tuBoundsMin.x < miBoundsMin.x) { izquierda.Add(tuBoxCol); } if (contacto.rigidbody && !pegadosRigid.Contains(contacto.rigidbody)) { pegadosRigid.Add(contacto.rigidbody); var tuLaycuarto = contacto.rigidbody.GetComponent <LayoutCuarto>(); if (tuLaycuarto) { pegados.Add(tuLaycuarto); var overLapX = Mathf.Min(tuBoundsMax.x, miBoundsMax.x) - Mathf.Max(tuBoundsMin.x, miBoundsMin.x); var overLapY = Mathf.Min(tuBoundsMax.y, miBoundsMax.y) - Mathf.Max(tuBoundsMin.y, miBoundsMin.y); if (overLapX > filtroOverlap || overLapY > filtroOverlap) { pegadosFiltrados.Add(tuLaycuarto); } else { pegadosTocandoPoco.Add(tuLaycuarto); } } } } } } RevisarMuros(); }
/// <summary> /// Removes the <see cref="Rigid"/>. /// </summary> /// <param name='r'> /// This <see cref="Rigid"/> will be remove from the world /// </param> public void RemoveRigid(Rigid r) { Rigids.Remove (r); }
public void LinearThreeBodyBasicTest() { World w = new World (); Rigid r1 = new Rigid (10, new Matrix (1, 1, 1)); w.AddRigid (r1); w.AddEffect (new Force (new Vector (1, 0, 0), r1)); Rigid r2 = new Rigid (20, new Matrix (1, 1, 1)); w.AddRigid (r2); Rigid r3 = new Rigid (20, new Matrix (1, 1, 1)); w.AddRigid (r3); w.AddEffect (new Force (new Vector (1, 0, 0), r3)); State s = new State (w, 0.001); s.Simulate (2); Assert.AreEqual (0.1, s.RigidStates [r1].LinearAcceleration.X, 0.001); Assert.AreEqual (0.2, s.RigidStates [r1].LinearVelocity.X, 0.001); Assert.AreEqual (0.2, s.RigidStates [r1].CenterOfMass.X, 0.001); Assert.AreEqual (0, s.RigidStates [r2].LinearAcceleration.Norm, 0.001); Assert.AreEqual (0, s.RigidStates [r2].LinearVelocity.Norm, 0.001); Assert.AreEqual (0, s.RigidStates [r2].CenterOfMass.Norm, 0.001); Assert.AreEqual (0.05, s.RigidStates [r3].LinearAcceleration.X, 0.001); Assert.AreEqual (0.1, s.RigidStates [r3].LinearVelocity.X, 0.001); Assert.AreEqual (0.1, s.RigidStates [r3].CenterOfMass.X, 0.001); }
public void ApplyForce(Vector3 force) { lastForce = force; Rigid.AddForce(force); }
public void Move(float timeModifer) { Rigid.AddForce(new Vector2(0, _force * timeModifer * speedModifer * (1 / _sizeModifer))); }