collider

Check if items are overlapping

女生的网名这么多〃 提交于 2021-02-17 05:52:21
问题 I have a few rooms which are placed randomly so I have to check if a room is overlapping. The rooms have a size of 10x10 and are for test reasons placed exactly side by side (they don't overlap in the scene). The Floor is a Transform which consists out of 1 or more Transforms (in this case out of one square but for other forms it it could be 2 or more). To check if they are overlapping I have this function which doesn't work. Debug log is always something between 3 and 61.. public bool

Child of Player not detecting collision with rigidbody on other object

╄→尐↘猪︶ㄣ 提交于 2021-02-11 15:21:40
问题 I have a player with a character controller, and a child object with a capsule collider extending a little bit out of the player's characterController to detect if the player jumps on a cube with a rigidbody on it. The child of the player has a tag called "hammer", and the rigidbody cube has a script on it. For some reason, the child is not detecting collisions with the rigidbody. It only does so when the player and the child is touching the rigidbody. Here is the code for the rigidbody cube:

For some reason, colliders collide, and I can fly

余生颓废 提交于 2020-01-05 04:11:14
问题 I am making a small prototype of a Unity 2D game. I have 2 colliders for my character. This helps me because I want my character to be able to wall jump. This means that when I collide with the wall, my collider detection script assumes that I am hitting 2 colliders, and helps me customize animations. //on the ground, change y position as necessary, and if you are pressing up, held = true if (InAirDetection.AirDetect == 1) { position.y += MoveUnitsPerSecond * verticalInput * Time.deltaTime;

Ways to detect 2D collision other than OnCollisionEnter2D

时光怂恿深爱的人放手 提交于 2019-12-17 17:15:22
问题 This might come off as a stupid question, but in an if statement, is it possible to check if the object is currently colliding with another object? Here is what I had thought of initially (in the code snipit bellow) but for some odd reason that I can't figure out, the variable onFloor is sometimes false when the object is being pushed upwards by the Platform. void OnCollisionEnter2D(Collision2D c) { switch(c.gameObject.tag) { case "Platform": onFloor = true; break; default: break; } } void

How to get random points from a Box Collider2D

本小妞迷上赌 提交于 2019-12-11 08:53:17
问题 I am trying to spawn particle effects at random points of a Box Collider2D. I know how to do this for a PolygonCollider2D but was just wondering if there is a similar way to do it for a Box Collider2D. I am trying to convert this code for a Box Collider. Can someone maybe point me in the right direction? PolygonCollider2D col = GetComponent<PolygonCollider2D>(); int index = Random.Range(0, col.pathCount); Vector2[] points = col.GetPath(index) Vector2 spawnPoint = Random.Range(0, points.Length

Restricting onMouseDown event on specific collides

陌路散爱 提交于 2019-12-11 07:55:10
问题 As you know, OnMouseDown work on mouse click but its run on every collider. My simple question is can i restrict OnMouseDown event to run on some specfic colliders not all collider as I am using some collider for trigger. Those some collider which i am using for trigger don't want to hit through onMouseDown. 回答1: You can try raycasting from the mouseposition and get the collider hit. This is what I would advice. This would do the trick: https://docs.unity3d.com/ScriptReference/Input

Find every colliding object in C# and Unity3D using OnTriggerStay

大兔子大兔子 提交于 2019-12-08 04:00:26
问题 As a gamer I'd phrase it like this: An AOE-Stun that stuns everyone it hits and then disappears. I have enemy objects with a class "EnemyMovement" attached to it. This class contains a function "Slow". I have a circle that has the class "StunSpell" attached to it. Now I want to call "Slow" once for every enemy object that collides with it. void OnTriggerStay2D(Collider2D other){ if (other.gameObject.tag == "Enemy") { //Here i want to find every gameobject (by tag "Enemy") other.GetComponent