I have a 3d object (a capsule) that I'm using in lieu of a character model because the project is going to be from a first person perspective. You can choose in the inspector whether to render the object's mesh or not. Since this object is meant to be invisible and only a hitbox, I want to know if raycasts and colliders will still detect it. I'm assuming yes because the object seems to behave normally with the physics, but I want to avoid complications in the future.
The only thing that matters for physics is the colliders and rigidbodies, It doesn't care about meshrenderers
Related
In order to be a rigidbody, my pirate ship collider has to be convex (unity gives me errors when it's not). I have a more detailed (non-convex) collider that i want to use for raycasts within the boat, but when i add it as a child object, the rigidbody automatically tries to use it.
Is there a way that i can have a seperate mesh collider as a child of a rigidbody? Any work-arounds?
Putting the detailed mesh on a seperate layer doesn't work. The only thing i can think of is making the ship out of many seperate convex colliders, but this is a solution that i want to avoid, as getting smooth internal curves would require many, many colliders.
Thank you for reading.
click here for gif show of what I want
I want to remove mesh of object when user click on object and also remove its collider to make another object fall from that removed mesh area...
I am using unity since last month so I don't have much experience and knowledge, please help me...
Creating the destructable ground particles
One way to achieve whats shown in the gif is by creating a prefab of e.g. a circle collider that is instantiated in the area of where the dirt is in your gif. It acts as a "ground particle" and keeps the objects above itself.
You instantiate a lot of them in the area so it acts as a big collider although it is actually a whole array of smaller colliders.
Implementing the interaction logic and deactivating the ground particles
Ater that you implement the functionality of dragging the mouse over the ground particles, removing them. That is also not difficult. Shoot raycasts into the screen at the postition of the mouse (remember to use Camera.ScreenToWorldPoint) and get the collision information (confer to https://docs.unity3d.com/ScriptReference/Collider2D.Raycast.html). With the collision information you can get the reference to the instance of your ground particle(raycasthit.other.gameobject) which is then disabled through script(gameobject.setActive(false)).
Context
I have in my project two elements. A player (just a cube) and some eyewears.
When the glasses aren't attached to the player, i want them to have properties of a Rigidbody. But when the eyewears are attached to the player, i want them to be a static object, so the player can process the collisions and physics.
I have tried:
DestroyElement(rigidbody) when the player pickup the eyewears. When he leaves them, i recreate the rigidbody with AddComponent
It worked nice, but in the future other elements will be attached and they will not share the same properties of rigidbody. I though maybe i could save the rigidbody instance, so when the player leaves the glasses i assign it to them. I could't.
AddComponent don't accept arguments.
Then i tried to set "kinematic mode" when my player wears the eyewears. It didn't go well, my player can't jump anymore and sometimes he glitches in the floor.
How can i resolve this?
GameObject.AddComponent does take an argument, or a generic argument (preferred):
go.AddComponent<RigidBody>();
this is also possible, but deprecated, since you lose type-safety:
go.AddComponent(typeof(RigidBody));
However, RigidBody is not meant to be added/removed, and in your case I would say that kinematic mode is the way to go... but I can't tell why you're experiencing weird results with it.
Thanks to R Astra i checked again the eyewear collisions and i found out the problem. I had enabled the Convex mesh.
The col was causing trouble because the back meshes were inside the player
So, quickly i copied that eyewear and generate a new mesh. It worked!
Thank you very much!
I have a Unity project in which there is a 2D game world that consists of static colliders to make the geometry solid to the characters that inhabit it. The player is a dynamic collider (with a non-kinematic rigidbody). There's also an enemy character that is also a dynamic collider. Both characters walk over the floor and bump into walls like I'd expect them to.
What I want to achieve is that the player and enemy are not solid to each other, so they can move through each other. I achieved this by putting the enemy and the player on separate layers and setting the collision matrix so that these layers do not collide with each other. The problem I'm having now, however, is that I do want to detect whether or not the enemy and the player ran into each other. I added a trigger collider to the enemy character, it's on the enemy layer which means it doesn't detect collisions with the player.
I thought of making a sub-gameobject for the enemy, put it on the player's layer, add a rigidbody and trigger collider to it and use that to detect collisions between the player and the enemy, but it feels so convoluted that it leaves me wondering if there isn't a more elegant solution for this.
Edit (2020-05-26): Nowadays you can tell the engine to ignore collisions between two given objects. Kudos to Deepscorn for the comment. Will leave the rest of the answer unchanged, and read with that in mind.
Yes, you need to create a child GameObject, with a trigger collider, and put it in a layer that interacts with the player layer.
No, you don't need to add a Rigidbody to the new GameObject, the parent's rigidbody already makes it a dynamic collider, so you will get OnTrigger events.
As a side note, just to keep things organized, if you create a child of the enemy don't put it in the player layer. For example, in the future you might need to disable the player's layer collision with itself. Furthermore, if your player interacts this way with many objects, I'd put a single trigger on the player instead of the enemies, on a separate PlayerTrigger layer, just to keep things simple.
Isn't there a simpler way? Not really. You definitely need non-interaction between the player and enemy colliders, but some kind of interaction between them too. So one of them needs to span two layers, or the whole interaction would be described by a single bool. The physics engine processes lots of information in one go, so you can set all the layers and collisions you want, but during the physics loop you have no further control on what happens. You can't tell the engine to ignore collisions between just two objects. Having only 32 layers, and having them behave in the rigid way they do are actually heavy optimizations. If you are concerned about performance for creating another layer, disable interaction between layers you don't need, like the trigger layer and the floor and walls, or layers that don't even touch.
Your alternative is doing it all by code, which is even less elegant. A single child capsule on the player doesn't sound that bad now, doesn't it?
I am beginner in Unity3d. i would like to ask you about creating new gameobject from exsiting objects in unity3d.
I want to to create new gameobject from existing spheres and squares in unity3d. Right now, i only drag them to become a group. In addition, I want spheres and squares in the new gameobject not to effect collider together.
The new object only collide with other outside objects. How i can do it?
More a question, i would like to create a hoop object in Unity3D, Has already hoop object existed in Unity3D? It has not existed yet, please tell me how to create it? and the space is at middle of hoop not to effect collider ??? Thanks so much,
If my question is not easy to understand, i will edit.
Sounds like you're after a Prefab.
Once you've created your prefab, you might want to Instantiate it.
To avoid collisions, make sure your prefab does not have a Collider component. Simply remove the component inside the prefab.
A hoop shape is also known as a taurus or a donut. This isn't available as a primitive in Unity3D but it is very easily created in 3D modelling programs and used within Unity3D's mesh import.
As Nathan pointed out, create a prefab from your objects.
It looks like you want your objects to act like a compound collider (see Compound Colliders section here). You need your objects to have Collider components, and you need to add RigidBody component to their parent GameObject.
About torus collider: http://forum.unity3d.com/threads/27906-Adding-a-new-collider-primitive