Two Objects Colliding

0 views
Skip to first unread message

Armanda Kicks

unread,
Aug 3, 2024, 4:19:07 PM8/3/24
to geabhoororos

I am following along with creating the Obstacle Game from Game Programming with Unity and C# by Casey Hardman. I have reached the point in the first few pages of Chapter 16 where you create a Hazard to kill the player. In the beginning stages, you write code that kills the player object if the player object collides with the hazard. I've followed the instructions (as far as I can tell) to the letter and yet when I created a sphere as a test hazard, assigned the script to it, and ran the player object into it, nothing happened when they collided. I thought maybe there was an error with the Hazard code, so I commented out the "when collide with object on player layer, kill player" code, wrote code to have it just write to the console when they collide, and tested it. Unfortunately, there doesn't seem to be any collision detection when these two objects touch each other. I've Googled "objects not colliding unity" and every combination of "collision not detected in unity" I can think of and none of the answers have helped so I'm posting here in hopes I get an answer. I'm including screenshots of the two objects and their settings, my physics settings in Unity, and the code I've written for both objects in hopes that someone can catch what I'm doing wrong.

Tagging the Player Object as Player (I saw a question that looked similar to mine so I thought maybe this would help; I'm not very familiar with Unity or C# yet so I'm unsure what or why things would help.)

This is my first unity project so I am fairly unfamiliar with everything the platform has. I am trying to log a message to the console when I have a my player game object run into a finish line. Both objects have Box Colliders on them and I have attached a C# script to the player object. Below is the code I have currently.

With the updated question and screenshots, the problem is that you're checking for the "Finish" tag but the "Finish" GameObject's tag is set to "Untagged" so the if (col.gameObject.tag == "Finish") statement will not evaluate to true.

1. Select the "Finish" GameObject, click the tag that says "Untagged" and create new tag named "Finish". If you already have this tag, change the tag of the "Finish" GameObject from "Untagged" to "Finish" and your if (col.gameObject.tag == "Finish") code should work.

If none of the two options above worked for you then OnCollisionEnter2D is not being called at-all. Put a Debug.Log outside the if statement like below and leave a comment about if there is a log or not.

I am trying to complete BlenderGuru's Quick Rigid Body Fun tutorial, but keep getting stuck when trying to add Rigid Body to the chain. My top chain link stays in mid-air, while the rest fall and collide with the floor and each other. But they should just hang in mid-air. According to the tutorial, the plane needs to be set to Passive under Rigid Body, and the top chain link should be Active , but unchecked in "Dynamic". The other chain links should all be Active and checked Dynamic. The top chain links stays as it should, but link#2 just falls right through. Any help appreciated :-)

Use the correct Collision Shape - on your example screenshot you show the first object as having Shape set to Mesh but check that all of your objects are similarly set. Convex Hull is more efficient but Mesh shape is required for interlocking objects and/or more complicated (non-convex) meshes.

Use a realistic scale - your example screenshot shows your Collision Sensitivity Margin set to 4cm which implies that 1 Blender Unit equates to 1 metre. Each link of your chain appears to be many blender units in size (when compared to the Grid which is visible in the screenshot). This means you have links that are many metres in length and will therefore behave as very large objects, with very large forces as they interact with each other. This can cause unstable simulations - especially if your 'steps per second' simulation setting is too low.

Ensure each object has its Scale applied - it's not clear if that is the case with your example. In order for Rigid Body objects to behave realistically, they need to have a consistent Scale in each of the X,Y,Z directions. To achieve this, select all links in the chain and press Ctrl+A and select 'Scale'.

Ensure the origin of each mesh is at its 'centre of gravity' - if you've created your chain using an Array modifier, split into its separate parts then the origins may be in the wrong place. Select the objects, click Set Origin in the tool panel (T) and select 'Origin to Centre of Mass'. A wrongly positioned origin (especially if it is outside the bounds of the mesh) can produce some very odd simulation results.

If the simulation still behaves erratically, you may need to increase the precision of the simulation - in particular the Scene/Rigid Body World/Steps Per Second - don't increase it too high as this can also cause problems with the simulation accuracy.

If you have addressed all of the above and still have a misbehaving simulation then it would help to upload an animation of what is occurring in your simulation (can tell a lot about how it's set up by how it moves and interacts) and/or upload your Blend file.

In order to demonstrate the difference applying the scale can make, here's a simulation where the chains have not had the scale applied (and have been stretched in one direction and have the scale of (1.0,1.0,5.0)) :

In Unity 5, I have a player shooting a projectile in aim to hit a boss, and inflict damage upon contact with the projectile. Though for some reason, the projectile and boss aren't colliding with each other.

EDIT: I found a temporary fix! Disabling the Kinematics of the boss allows for both objects to collide, and successfully display a debug message!Just a problem though; I don't want the boss to freely float around in space. I use the kinematic to ensure it stays put at all times until told to by scripts.

It turns out that you can't collide objects that both have "Is Kinematic" enabled. To get around this personally, I just unchecked "Is Kinematic" from the projectile and set it's gravity to 0, so it doesn't fly down.

i tried removing the condition, but that didnt work. what i will probably end up doing is just have a different collision event for each monster, and check if the object is colliding with a member of the group. tedious but its what im gonna need to do.

Can someone explain to me why the objects are colliding with each other before touching? This happens when I scale down the objects. The collider bounds appear to scale appropriately yet the objects still collide before touching.

I have a semi-organized / semi-randomized cluster of objects (they happen to be meshes). They roughly follow a guide curve. Since each object will eventually be fabricated, they can't intersect each other.

I'm using the "Collision Many Many" component to cull those that intersect, but when I use the output of this component with a "Cull Pattern" component, it removes all the objects that intersect each other. I'd like to remove the fewest possible so none intersect anymore.

Culling objects with more than 2 collisions won't get rid of all the collisions, only a select few. Many only have one collision... I just want to get rid of one of the offenders. Right now, if two objects collide, I cull them both. I only need to cull one or the other.

In the above case there is certainly a solution with 20 objects (bottom left corner I created your shape) but galapagos can't find it even with 1 million possible seed values on the [random reduce] component :(

Lately I've been thinking about it a different way: instead of creating a distribution, then removing overlaps, could I create a distribution that has no overlaps? That is, could I place the objects in a way so that each placement is aware of the other objects around it? I never started with this option because it seemed to immediately require looping. I try to avoid those solutions if possible.

since you never uploaded any files we had to keep this discussion strictly to the point (remove minimum number of objects in order to have no collisions). We have no clue as to where those objects are coming from, just that some of them are colliding. If you are ok with uploading a file we can maybe think of ways to avoid collisions in the first place (using a loop plugin, as you suggested, or even using something like kangaroo's springs or box collide or...)

In Affinity Designer, I'm trying to figure out the easiest way to create gaps in between colliding objects. A lot of modern logos and icons have space in between their intersecting areas. My attachment is an example of this. At one point, I got it, but now I'm getting confused. I am trying to create a scissor icon this style, but it's getting over my head.

Thank you for everyone's help so far, but I'm having a hard time understanding some of the steps. Let me start fresh since the circle and triangle was just a bold example. I am recreating icons I made. The example image here shows two bucket icons. The first is the original, and the second is in the middle of being modified. Before, all my icons had inner strokes, but now I want to have gap space where the outer strokes are. Taking that second one, what is the best way to do it?

Please clarify. What is the desired final result? In the right hand thumbnail example, I see 4 shapes. The paint bucket handle, the bucket, the inside of the bucket, and the pouring paint. The body of those shapes use 3 different blue colors. All are outlined by the darker blue color.

With the Colour and Layers panels visible, open the example that I posted and go to the Layers panel. Hide the 'Before' layer and then unhide the 'After' layer. The stroke on the red curve will look grey, but if you expand the layer tree, select the red curve and select the stroke ring in the Colour panel you'll see that it's actually a black stroke with 50% opacity. This enables you to see whether it's overlapping the rest of the 'pie' as you move it around. :)

c80f0f1006
Reply all
Reply to author
Forward
0 new messages