//Script que faz o Layer Collision Matrix nao ignorar colliders com trigger public static void UpdateCollisionLayerMatrix() { List <Tuple <Collider2D, Collider2D> > collidersToUpdate = new List <Tuple <Collider2D, Collider2D> >(); Collider2D[] colliders = FindObjectsOfType(typeof(Collider2D)) as Collider2D[]; if (colliders == null) { return; } foreach (Collider2D colliderA in colliders) { foreach (Collider2D colliderB in colliders) { if (colliderA.gameObject == colliderB.gameObject) { continue; } if (Physics2D.GetIgnoreLayerCollision(colliderA.gameObject.layer, colliderB.gameObject.layer)) { collidersToUpdate.Add(new Tuple <Collider2D, Collider2D>(colliderA, colliderB)); } } } foreach (Tuple <Collider2D, Collider2D> tuple in collidersToUpdate) { Physics2D.IgnoreLayerCollision(tuple.ItemA.gameObject.layer, tuple.ItemB.gameObject.layer, false); if (!tuple.ItemA.isTrigger && !tuple.ItemB.isTrigger) { Physics2D.IgnoreCollision(tuple.ItemA, tuple.ItemB, true); } } }
private void FixedUpdate() { // Checks if player is touching the ground m_Grounded = false; Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround); foreach (Collider2D temp_collider in colliders) { // Checks if collider and player are supposed to collide bool shouldCollide = !(Physics2D.GetIgnoreCollision(temp_collider, playerCollider) || Physics2D.GetIgnoreLayerCollision(temp_collider.gameObject.layer, gameObject.layer)); if (temp_collider.gameObject != gameObject && !temp_collider.isTrigger && shouldCollide) { m_Grounded = true; // Drops down platform if (dropDown && temp_collider.gameObject.layer == LayerMask.NameToLayer("EnvironmentObjects")) { StartCoroutine(DropDownPlatform(temp_collider)); } } } animator.SetBool("IsJumping", !m_Grounded); Move(horizontalMove); jump = false; dropDown = false; }
void Start() { timeScaler = GetComponent <TimeScaler2d>(); timeScaler.originalVelocity = transform.right * speed; Gradient g = new Gradient(); g.FromColor(color); TrailRenderer tr = GetComponent <TrailRenderer>(); tr.colorGradient = g; prevPos = transform.position; var layer = gameObject.layer; layerMask = 0; for (int i = 0; i < 32; i++) { if (!Physics2D.GetIgnoreLayerCollision(layer, i)) { layerMask |= 1 << i; } } }
public static void Initialize() { s_layerCollision3DMask = new LayerMask[32]; for (int i = 0; i < 32; ++i) { for (int j = 0; j < 32; ++j) { bool isIgnored = Physics.GetIgnoreLayerCollision(i, j); if (!isIgnored) { s_layerCollision3DMask[i].value = s_layerCollision3DMask[i].value | (1 << j); } } } s_layerCollision2DMask = new LayerMask[32]; for (int i = 0; i < 32; ++i) { for (int j = 0; j < 32; ++j) { bool isIgnored = Physics2D.GetIgnoreLayerCollision(i, j); if (!isIgnored) { s_layerCollision2DMask[i].value = s_layerCollision2DMask[i].value | (1 << j); } } } }
public void Pull() { m_Gravity = Physics2D.gravity; m_VelocityIterations = Physics2D.velocityIterations; m_PositionIterations = Physics2D.positionIterations; m_VelocityThreshold = Physics2D.velocityThreshold; m_MaxLinearCorrection = Physics2D.maxLinearCorrection; m_MaxAngularCorrection = Physics2D.maxAngularCorrection; m_MaxTranslationSpeed = Physics2D.maxTranslationSpeed; m_MaxRotationSpeed = Physics2D.maxRotationSpeed; m_MinPenetrationForPenalty = Physics2D.defaultContactOffset; m_BaumgarteScale = Physics2D.baumgarteScale; m_BaumgarteTimeOfImpactScale = Physics2D.baumgarteTOIScale; m_TimeToSleep = Physics2D.timeToSleep; m_LinearSleepTolerance = Physics2D.linearSleepTolerance; m_AngularSleepTolerance = Physics2D.angularSleepTolerance; m_QueriesHitTriggers = Physics2D.queriesHitTriggers; m_QueriesStartInColliders = Physics2D.queriesStartInColliders; m_ChangeStopsCallbacks = Physics2D.changeStopsCallbacks; for (int row = 0; row < 32; row++) { for (int col = 0; col < 32; col++) { IgnoreLayerCollision(row, col, Physics2D.GetIgnoreLayerCollision(row, col)); } } }
// Update is called once per frame void Update() { if (!GameManager.Instance.IsPause && !LevelManager.Instance.IsGameOver) { if (m_Rigidbody2D.velocity.y != 0) { if (transform.localPosition.y > m_lastY) { if (!Physics2D.GetIgnoreLayerCollision(LayerMask.NameToLayer("Ball"), LayerMask.NameToLayer("Platform"))) { Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Ball"), LayerMask.NameToLayer("Platform"), true); } } else { if (Physics2D.GetIgnoreLayerCollision(LayerMask.NameToLayer("Ball"), LayerMask.NameToLayer("Platform"))) { Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Ball"), LayerMask.NameToLayer("Platform"), false); } } } m_lastY = transform.localPosition.y; //Debug.Log(m_Rigidbody2D.velocity.y); } }
void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Clone") { plateWeight++; Physics2D.GetIgnoreLayerCollision(9, 9); } }
public static void Assimilate(LSBody body) { if (CachedIDs.Count > 0) { id = CachedIDs.Pop(); } else { id = PeakCount; PeakCount++; } SimObjectExists [id] = true; SimObjects [id] = body; body.ID = id; for (i = 0; i < id; i++) { other = SimObjects [i]; if (!Physics2D.GetIgnoreLayerCollision(other.cachedGameObject.layer, body.cachedGameObject.layer)) { colPairIndex = i * MaxSimObjects + id; pair = CollisionPairs[colPairIndex]; if (pair == null) { pair = new CollisionPair(); CollisionPairs [colPairIndex] = pair; } FastCollisionPairs.Add(pair); pair.Initialize(other, body); CollisionPairCount++; } } for (j = id + 1; j < PeakCount; j++) { other = SimObjects [j]; if (!Physics2D.GetIgnoreLayerCollision(other.cachedGameObject.layer, body.cachedGameObject.layer)) { colPairIndex = id * MaxSimObjects + j; pair = CollisionPairs[colPairIndex]; if (pair == null) { pair = new CollisionPair(); CollisionPairs [colPairIndex] = pair; } FastCollisionPairs.Add(pair); pair.Initialize(body, other); CollisionPairCount++; } } AssimilatedCount++; }
private void Awake() { // Se estiver ignorando colisões com inimigos if (Physics2D.GetIgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("Enemies"))) { // Para de ignorar Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("Enemies"), false); } }
public bool Physics2DLayerCollisionMatrix() { const int numLayers = 32; for (var i = 0; i < numLayers; ++i) for (var j = 0; j < i; ++j) if (Physics2D.GetIgnoreLayerCollision(i, j)) return false; return true; }
protected override void Awake() { base.Awake(); Anim = GetComponent <Animator>(); Physics2D.GetIgnoreLayerCollision(8, 9); if (transform.parent == null) { return; } }
public bool CheckFallPlatformInput() { if (Input.GetButtonDown("Jump") && (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))) { bool b = Physics2D.GetIgnoreLayerCollision(0, 12); StartCoroutine("FallFromPlatform"); return(true); } return(false); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.name != "Enemy" && !other.isTrigger && !Physics2D.GetIgnoreLayerCollision(other.gameObject.layer, this.gameObject.layer)) { //this.collider2D.enabled = false; this.transform.localPosition = originalPosition; this.gameObject.SetActive(false); //this.collider2D.enabled = true; } }
void OnCollisionEnter2D(Collision2D other) { //Physics2D.IgnoreCollision(other.gameObject.GetComponent<Collider2D>(), GetComponent<Collider2D>()); //.GetIgnoreLayerCollision(9, 9); if (other.gameObject.tag == "Player") { Physics2D.IgnoreCollision(other.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>()); Physics2D.GetIgnoreLayerCollision(9, 10); } if (other.gameObject.tag == "Boarder") { Destroy(gameObject); } if (other.gameObject.tag == "lazer") { Physics2D.GetIgnoreLayerCollision(9, 9); Physics2D.IgnoreCollision(other.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>()); } if (other.gameObject.tag == "Wall") { if (AssosiatedWeapon.WeaponLevel >= 5 || AssosiatedWeapon.weaponname == "Rifle") { foreach (ContactPoint2D contact in other.contacts) { Vector3 normal = contact.normal; velocity = Vector3.Reflect(velocity, normal); } } else { Destroy(gameObject); } } if (other.gameObject.tag == "enemy") { if (other.gameObject.GetComponent <Enemymovement>() != null) { int health = other.gameObject.GetComponent <Enemymovement>().health; other.gameObject.GetComponent <Enemymovement>().health -= damage * charactermovement2.damageMultiplyer; damage -= health; } else { other.gameObject.GetComponent <KamikazeScript> ().health -= damage * charactermovement2.damageMultiplyer; } if (player.activeWeapon.name != "Rifle" || other.gameObject.GetComponent <Enemymovement>().health > 0) { Destroy(gameObject); } } }
public static bool RequireCollisionPair(LSBody body1, LSBody body2) { if ( Physics2D.GetIgnoreLayerCollision(body1.Layer, body2.Layer) == false && (!body1.Immovable || !body2.Immovable) && (!body1.IsTrigger || !body2.IsTrigger) && (body1.Shape != ColliderType.None && body2.Shape != ColliderType.None)) { return true; } return false; }
public static bool RequireCollisionPair(LSBody body1, LSBody body2) { if ( !Physics2D.GetIgnoreLayerCollision(body1.cachedGameObject.layer, body2.cachedGameObject.layer) && (!body1.Immovable || !body2.Immovable) && (!body1.IsTrigger || !body2.IsTrigger)) { return(true); } return(false); }
public static int CreateLayerMask(int layer) { int layermask = 0; for (int i = 0; i < 32; i++) { if (!Physics2D.GetIgnoreLayerCollision(layer, i)) { layermask = layermask | 1 << i; } } return(layermask); }
/// <summary> /// Gets the collision mask of the indicated layer /// </summary> /// <param name="layer"></param> /// <returns></returns> public static int GetCollisionMask2D(int layer) { int result = 0; for (int i = 0; i < 32; i++) { if (!Physics2D.GetIgnoreLayerCollision(layer, i)) { result = result | 1 << i; } } return(result); }
private void CreateLayerMask() { _LayerMask = 0; int layer = gameObject.layer; for (int i = 0; i < 32; i++) { if (!Physics2D.GetIgnoreLayerCollision(layer, i)) { _LayerMask = _LayerMask | 1 << i; } } }
/// <summary> /// Creates an array of masks for collisions/raycasts in 2D physics /// Useful for mirroring collision behavior. /// </summary> /// <returns>the masks for each layer</returns> public static int[] CollisionLayers2D() { int[] collisionMask = new int[32]; for (int i = 0; i < 32; i++) { collisionMask[i] = 0; for (int j = 0; j < 32; j++) { collisionMask[i] |= (Physics2D.GetIgnoreLayerCollision(i, j)) ? 0 : (1 << j); } } return(collisionMask); }
private void CloneFromPhysics2D() { LayersDic layersDic; LayerCollsDic collsDic; this.GetCloneInfos( (id1, id2) => Physics2D.GetIgnoreLayerCollision(id1, id2), out layersDic, out collsDic ); this.Clone(layersDic, collsDic); }
public void Move(float MoveX, float MoveY) { movement.Set(movementX, movementY); check_MovementLimits(); if (Dashing()) { if (!hole_coll) { movement = dash_direction; } animator.SetBool("dash", true); god_ModeAction.timerTotGodMode = 0.2f; god_ModeAction.godMode = true; if (PlayerNum == Enum_PlayerNum.PlayerOne) { rope_system.set_mov_P1(movement * dash_power); } else if (PlayerNum == Enum_PlayerNum.PlayerTwo) { rope_system.set_mov_P2(movement * dash_power); } } else { animator.SetBool("dash", false); if (PlayerNum == Enum_PlayerNum.PlayerOne) { rope_system.set_mov_P1(movement * speed); //Reactive the collision betwen the Holes and the player when is not dashing if (Physics2D.GetIgnoreLayerCollision(19, 21)) { Physics2D.IgnoreLayerCollision(19, 21, false); } } else if (PlayerNum == Enum_PlayerNum.PlayerTwo) { rope_system.set_mov_P2(movement * speed); //Reactive the collision betwen the Holes and the player when is not dashing if (Physics2D.GetIgnoreLayerCollision(20, 21)) { Physics2D.IgnoreLayerCollision(20, 21, false); } } } }
// Use this for initialization void Start() { pos = transform.position; hj = GetComponent <HingeJoint2D>(); rigid = GetComponent <Rigidbody2D>(); motor = new JointMotor2D(); minAngle = transform.localEulerAngles.z; status = "Idle"; Physics2D.GetIgnoreLayerCollision(8, 9); }
public static void ReadCollisionLayerMatrix() { for (int i = 0; i < 32; i++) { int mask = 0; for (int j = 0; j < 32; j++) { if (!Physics2D.GetIgnoreLayerCollision(i, j)) { mask |= 1 << j; } } masksByLayer.Add(i, mask); } }
private static bool IgnoreAllCollisionsInPoint(Vector2 point, Collider2D collider) { var layer = collider.gameObject.layer; var colliders = Physics2D.OverlapPointAll(point); foreach (Collider2D item in colliders) { if (!item.isTrigger && !Physics2D.GetIgnoreLayerCollision(layer, item.gameObject.layer)) { return(false); } } return(true); }
void InitializeCollisionMask() { int objectLayer = gameObject.layer; collisionMask = 0; // Cycle through all layers to find which collide and do not collide with the objects layers for (int i = 0; i < 32; i++) { if (!Physics2D.GetIgnoreLayerCollision(objectLayer, i)) { // If so, add to the collision mask collisionMask = collisionMask | 1 << i; } } }
public static int GetLayerCollisionMask(int layer) { int mask = 0; for (int i = 0; i < 32; i++) { bool ignored = Physics2D.GetIgnoreLayerCollision(layer, i); if (!ignored) { mask |= 1 << i; } } return(mask); }
public bool Physics2DLayerCollisionMatrix() { const int NUM_LAYERS = 32; for (var i = 0; i < NUM_LAYERS; ++i) { for (var j = 0; j < i; ++j) { if (Physics2D.GetIgnoreLayerCollision(i, j)) { return(false); } } } return(true); }
public static void PopulateCollisionMatrix() { _collisionMatrix = new Dictionary <int, int>(); for (int i = 0; i < 32; i++) { int mask = 0; for (int j = 0; j < 32; j++) { if (!Physics2D.GetIgnoreLayerCollision(i, j)) { mask |= 1 << j; } } _collisionMatrix.Add(i, mask); } }
public static bool Physics2DLayerCollisionMatrix() { const int numLayers = 32; for (var i = 0; i < numLayers; ++i) { for (var j = 0; j < i; ++j) { if (Physics2D.GetIgnoreLayerCollision(i, j)) { return(false); } } } return(true); }