public void ChangeType(RigidbodyType2D type) { foreach (Rigidbody2D rb in _Rigidbodys) { rb.bodyType = type; } }
public virtual void freeze(float dur) { FreezeTime = Time.time + dur; if (Frozen) { return; } Frozen = true; foreach (Animator anim in this.GetComponentsInChildren <Animator>()) { anim.enabled = false; //May not apply to all animators } Am.am.sound(Am.am.M.chooseSound(Am.am.M.FreezeSound1, Am.am.M.FreezeSound2, Am.am.M.FreezeSound3, Am.am.M.FreezeSound4)); //FreezeSprite.enabled = true; rbodtype = MyRigidbody.bodyType; usedgrav = this.MyRigidbody.gravityScale; if (rbodtype == RigidbodyType2D.Dynamic) { MyRigidbody.bodyType = RigidbodyType2D.Dynamic; } this.MyRigidbody.velocity = new Vector2(0f, 0f); this.MyRigidbody.gravityScale = 1f; MyFreezeFlare.Play(true); MyFreezeDust.Play(true); MyFreezeSparkles.Play(true); }
/*void InitialzeGhostPlayer() * { * ghostPlayer = Instantiate(Resources.Load("GhostPlayer", typeof(GameObject)) as GameObject); * ghostPlayer.GetComponent<PlayerController>().Initialize(); * ghostPlayer.transform.position = player.transform.position; * ghostPlayer.transform.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; * ghostReplay = new GhostReplay(); * ghostReplay.InitGhostList(); * //ghostReplay.SetGhostList(); * }*/ public void SetPlayerBodyType(RigidbodyType2D type) { if (player != null) { player.GetComponent <Rigidbody2D>().bodyType = type; } }
void SyncToClients() { // only update if they have changed more than Sensitivity Vector2 currentVelocity = syncVelocity ? target.velocity : default; float currentAngularVelocity = syncAngularVelocity ? target.angularVelocity : default; bool velocityChanged = syncVelocity && ((previousValue.velocity - currentVelocity).sqrMagnitude > velocitySensitivity * velocitySensitivity); bool angularVelocityChanged = syncAngularVelocity && ((previousValue.angularVelocity - currentAngularVelocity) > angularVelocitySensitivity * angularVelocitySensitivity); if (velocityChanged) { velocity = currentVelocity; previousValue.velocity = currentVelocity; } if (angularVelocityChanged) { angularVelocity = currentAngularVelocity; previousValue.angularVelocity = currentAngularVelocity; } // other rigidbody settings bodyType = target.bodyType; gravityScale = target.gravityScale; drag = target.drag; angularDrag = target.angularDrag; }
private void SetBodyType(Rigidbody2D body, RigidbodyType2D type) { if (body.bodyType != type) { body.bodyType = type; } }
// Release is like return, but to the previously attached Hollow Block's position // To be called by Hollow Blocks only or self public void Release() { this.WearDefaultSkin(); this.isAssigned = false; this.SetCarried(false); this.GetRigidBody2D().bodyType = RigidbodyType2D.Dynamic; gameObject.transform.SetParent(detachedManagerParent.gameObject.transform); this.boxCollider.isTrigger = false; // this.EnableRigidBody (); this.GetRigidBody2D().velocity = Vector2.zero; this.GetRigidBody2D().angularVelocity = 0f; gameObject.transform.position = this.GetHollowBlock().gameObject.transform.position; gameObject.transform.eulerAngles = Vector3.zero; // To add force this.GetRigidBody2D().AddRelativeForce(Random.onUnitSphere * speed); this.GetRigidBody2D().AddTorque(torque); // gameObject.transform.SetParent (this.GetDetachedManagerParent().gameObject.transform); if (hollowBlock != null) { hollowBlock.UpdateStabilityLabel(); } this.SetHollowBlock(null); }
private void ConfigurePlaybackPhysics() { Rigidbody2D targetRB = GetTargetRigidbody(); originalRBType = targetRB.bodyType; targetRB.bodyType = RigidbodyType2D.Kinematic; }
/* ************* * CREATION * ===============*/ private logic_rope_node createStartNode(GameObject originalNode, RigidbodyType2D bodyType) { // CREATE A TEMP NODE int index = this._ropeNodes.Count; GameObject temp = new GameObject(); temp.name = "rope_node_START_" + index; temp.transform.parent = this.gameObject.transform; temp.tag = "particle_object"; Vector3 pos = originalNode.transform.position; temp.transform.position = new Vector3(pos.x, pos.y, this.transform.position.z); // Fix Z temp.layer = 13; Rigidbody2D tempBody = temp.AddComponent <Rigidbody2D>(); tempBody.bodyType = bodyType; tempBody.mass = 100f; tempBody.angularDrag = 1f; logic_rope_node node = temp.AddComponent <logic_rope_node>(); node.setRopeController(this); node.body = tempBody; return(node); }
void OnEntityStateChanged(M8.EntityBase ent) { if (unit.prevState == state) { if (applyRigidbodyMode) { unit.body.bodyType = mPreviousRigidbodyMode; } } if (unit.state == state) { unit.physicsEnabled = true; mCurVelocity = mDir * mInitSpeed; if (applyRigidbodyMode) { mPreviousRigidbodyMode = unit.body.bodyType; unit.body.bodyType = rigidbodyMode; } if (unit.body.bodyType == RigidbodyType2D.Dynamic) { unit.body.velocity = mCurVelocity; } } }
public void SetRigidbodyType(RigidbodyType2D type) { if (_RigidBody != null) { _RigidBody.bodyType = type; } }
private void Start() { Instance = this; originalBodyType = rb2d.bodyType; speed = defaultSpeed; }
protected IEnumerator Knockback(Vector2 dir, float force) { isKnockedBack = true; PlayerState lastState = playerState; RigidbodyType2D lastType = rb.bodyType; playerState = PlayerState.IMMOBILE; bool prevPath = false; if (path) { prevPath = path.enabled; path.enabled = false; } rb.bodyType = RigidbodyType2D.Dynamic; rb.AddForce(dir * force, ForceMode2D.Impulse); yield return(new WaitForSeconds(0.3f)); if (path) { path.enabled = prevPath; } rb.bodyType = lastType; playerState = lastState; isKnockedBack = false; }
public void CambiarTiempo(int tiempo, RigidbodyType2D type, bool istrigger, bool rend) { TimeToExist = tiempo; GetComponent <Rigidbody2D>().bodyType = type; GetComponent <Collider2D>().isTrigger = istrigger; GetComponent <Renderer>().enabled = rend; }
public void StartFalling() { bodyType = rb.bodyType; rb.bodyType = RigidbodyType2D.Kinematic; IsFalling = true; rb.velocity = Vector2.down * FallSpeed; }
public void ToggleGravity() { foreach (Part part in parts) { RigidbodyType2D bodyType = part.GetComponent <Rigidbody2D>().bodyType; part.GetComponent <Rigidbody2D>().bodyType = bodyType == RigidbodyType2D.Kinematic ? RigidbodyType2D.Dynamic : RigidbodyType2D.Kinematic; } }
void OnRigidbodyType2DChanged(RigidbodyType2D _, RigidbodyType2D newValue) { if (IgnoreSync) { return; } target.bodyType = newValue; }
public void Drop() { this.WearDefaultSkin(); this.SetCarried(false); this.GetRigidBody2D().bodyType = RigidbodyType2D.Dynamic; gameObject.transform.SetParent(detachedManagerParent.gameObject.transform); this.boxCollider.isTrigger = false; StartCoroutine(DropRoutine()); }
private void SetComponentsState(bool state, RigidbodyType2D type) { _weapon.SetActive(state); _fuelParticles.SetActive(state); _spriteRenderer.enabled = state; _blackSprite.enabled = state; _boxCollider2D.enabled = state; _playerMovementOnline.enabled = state; _rigidbody2D.bodyType = type; }
public void FillDrop(HollowBlock hollowBlock) { this.WearDefaultSkin(); this.SetCarried(false); this.GetRigidBody2D().bodyType = RigidbodyType2D.Dynamic; gameObject.transform.SetParent(detachedManagerParent.gameObject.transform); this.boxCollider.isTrigger = false; this.Unobserve(); hollowBlock.Absorb(this); }
void CmdSendRigidbodyType2D(RigidbodyType2D bodyType) { // Ignore messages from client if not in client authority mode if (!clientAuthority) { return; } this.bodyType = bodyType; target.bodyType = bodyType; }
private bool isDynamic = false; //whether or not the object's Rigidbody is Dynamic void Start() { lastPosition = transform.parent.position; //initialize position //Check if Rigidbody is Dynamic RigidbodyType2D rbtype = GetComponentInParent <Rigidbody2D>().bodyType; if (rbtype == RigidbodyType2D.Dynamic) { isDynamic = true; } }
// Start is called before the first frame update void Start() { _timeStore = new Stack <Time>(); _rb = GetComponent <Rigidbody2D>(); _animator = GetComponentInChildren <Animator>(); if (_animator != null) { _hasAnimator = true; } _rbType = _rb.bodyType; }
public void Save(Rigidbody2D rigidbody) { // TODO: would it make more sense to use RigidbodyType2D.Static here? BodyType = rigidbody.bodyType; rigidbody.bodyType = RigidbodyType2D.Kinematic; Velocity = rigidbody.velocity; rigidbody.velocity = Vector3.zero; AngularVelocity = rigidbody.angularVelocity; rigidbody.angularVelocity = 0.0f; }
private void Awake() { _animator = GetComponent <Animator>(); _audioSource = GetComponent <AudioSource>(); _rigidBody2D = GetComponent <Rigidbody2D>(); // if(StringUtil.IsNonNullNonEmpty(animationHitTrigger)) { // animationHitTriggerId = Animator.StringToHash(animationHitTrigger); // } _rigidBody_type = _rigidBody2D.bodyType; }
private void Update() { rb = GetComponent <Rigidbody2D>().bodyType; if (rb == RigidbodyType2D.Kinematic) //Objeto é do tipo Kinematic enquanto está vivo, e vira Dynamic quando morre. { // Also, condição para que inimigo pare de atirar após morrer. timer += Time.deltaTime; if (timer >= fireRate) { Fire(); timer = 0; } } }
public void OnPickUp() { var rb = GetComponent <Rigidbody2D>(); if (rb != null) { this.originalBodyType = rb.bodyType; rb.bodyType = RigidbodyType2D.Kinematic; rb.simulated = false; // Reset the rotation rb.transform.localRotation = new Quaternion(); } }
public void SetFreeze(RigidbodyType2D type) { rgbd.bodyType = type; switch (rgbd.bodyType) { case RigidbodyType2D.Static: sprt.color = new Color32(83, 53, 74, 255); break; case RigidbodyType2D.Dynamic: sprt.color = firstColor; break; } }
/* * Rammasse l'objet en parametre. * Si le personnage tient deja un objet, ne fait rien * -> bool : true si l'objet a ete ramasse, sinon false */ public bool pickBigObject(Rigidbody2D obj) { if (bigObj) { return(false); } bigObj = obj; obj.BroadcastMessage("OnPickup", SendMessageOptions.DontRequireReceiver); bigObjOldState = bigObj.bodyType; bigObj.bodyType = RigidbodyType2D.Kinematic; bigObjOldLayer = obj.gameObject.layer; obj.gameObject.layer = gameObject.layer; return(true); }
private void SetGrabObjectPhysics(RigidbodyType2D type) { if (GrabbedObject == null) { return; } var body = GrabbedObject.GetComponent <Rigidbody2D>(); if (body != null) { body.bodyType = type; } }
private IEnumerator MovePower() { colide = false; IceBlockPhysics blockPhysics = iceBlock.GetComponent <IceBlockPhysics>(); rbType = blockPhysics.RigidbodyGetType(); blockPhysics.RigidbodyChange(RigidbodyType2D.Static); GameObject cloneOfTargetedObject = Instantiate(blockPhysics.gameObject); listOfColor.Add(blockPhysics.gameObject.GetComponent <SpriteRenderer>().color); blockPhysics.gameObject.GetComponent <SpriteRenderer>().color = color[1]; //GetCollider var collider2d = cloneOfTargetedObject.GetComponent <Collider2D>(); collider2d.isTrigger = true; BoxColliderScale.ScaleCollider(collider2d, true); SpriteRenderer spriteClone = cloneOfTargetedObject.GetComponent <SpriteRenderer>(); spriteClone.sortingOrder = 15; while (true) { if (playerController.buttonUp) { uncheckPower = false; if (!colide) { blockPhysics.transform.position = cloneOfTargetedObject.transform.position; GameUI.Instance.UsedPower(true); } else { GameUI.Instance.UsedPower(false); } Destroy(cloneOfTargetedObject.gameObject); blockPhysics.gameObject.GetComponent <SpriteRenderer>().color = listOfColor[0]; blockPhysics.RigidbodyChange(rbType); listOfColor.Clear(); uncheckPower = true; break; } CheckColision(spriteClone); Vector2 position = Camera.main.ScreenToWorldPoint(Input.mousePosition); cloneOfTargetedObject.transform.position = position; yield return(new WaitForEndOfFrame()); } }