Is it possible to have collision on a child object moves its parent in Unity? - unity3d

I'm attempting to develop a 2.5D fighting game in Unity, and I've gotten to the point of attempting to make basic collision between players function. I'm attempting to do so via collision boxes like those seen in the video here: (4:01 if the timestamp doesn't work)
https://youtu.be/m5yRLhAx4Ro?t=241
What I have attempted to do in order to replicate this system of collision is to make a collision box prefab with a dynamic rigidbody and box collider. A script instantiates a new one as a child of the player and destroys any existing ones whenever the collision box's size and position need to be changed. However, I've found that this does not work. I can get the players to collide with each other, but when I disable that collision by putting the parents on a layer that doesn't collide with any others, the collision boxes themselves will just phase through each other along with their parent objects, the players.
What I want is a system in which the players will be responsible for their movement, but the child objects (the collision boxes) will function as the players' colliders. If anyone knows a way of doing this, or any other way of achieving this sort of system, I would greatly appreciate the help.

Just add a Fixed Joint on the child object then connect it with the parent rigidbody.

Related

How can I remove small part of collider of game object in unity 2d

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)).

How can i make two game objects are pass through each other in Unity?

I made two game objects, player and enemy.
I hope two game objects collision detect and they are pass through each other.
Thus i put a check mark objects collider's 'is Trigger' and objects's 'rigid body'. So, i expected that objects are pass through each other.
But, player and enemy crashed each other. Why player and enemy crash?
i want two objects pass through each other.
help me please.
A collider marked as a trigger should not cause physical collisions with an incoming Rigidbody (see here). Check and see if one of the player or any objects has a child with a collider that is not marked as a trigger.
Also note that a CharacterController component will be constrained by collisions, as mentioned in the documentation. CharacterControllers do not have a trigger option, so you will have to disable collisions through a different method. The most common methods are using Physics.IgnoreCollision or changing the layers of the objects and disabling collisions between layers in Edit -> Project Settings -> Physics. See here for more details: Layer-based collision detection and How to Ignore Collision between Objects.

Unity physics scenes copy all colliders from main scene

I am trying to use Unity's physic scenes to perform some simulations outside of the main scene. That being said, I need all of the colliders from the main scene in the physics scenes. What is the easiest way to create a physics scene with all of the existing colliders from another scene? Do I have to loop through everything, use SceneManager.MoveGameObjectToScene(...) for every object then move them back at the end of the simulation? This doesn't seem scalable.
EDIT
I have a multiplayer game, when I get responses from the server I am taking their velocity and the servers position, then applying all local movement since that packet was sent via Physics2D.Simulate() to have the velocities correctly applied to the position. Now I need to do the same for the projectiles so I would need the map colliders as well as the player's. I was reading the best thing to do for physics sims is use physic scenes. If I call Physics2D.Simulate() in the main scene for more than 1 set of data (player movement vs projectiles) places I got a lot of screen jitter. Moving these simulations into separate scenes removes the jitter.
The only alternative I see is re-implementing Physics2D.Simulate() myself which seems like a bad (and complicated) idea.
Thanks.
I ended up only needing the collider and rigid body so I created an empty object in the physics scene with these 2 objects. Every time I needed to run the simulation, I would update the rigid body with the current players rigid body details then run the sim and apply the output velocity from the sim to the players rigid body again.

Make two physics objects not collide but do detect collisions in Unity

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?

Unity finding closest transform when collided

I am currently using Unity 3D to create a 3rd person game. But I am having an issue with trying to parent to the closest child transform of an object:
whenever the player comes into contact with a specific tagged gameObject, the collided game object becomes a child of the player. However I want it to child itself to the closest bone it collided at.
So far i have set up a for loop that searches for the closest local position to the collided object and found the Vector3 of the closest bone.
But now I want it to child itself to the transform with that local Vector3. If anyone has any advice on how to do this then this would be greatly appreciated. If you would like to see example code, then just say.
Thanks
One solution is to attach colliders to all all bones and then you can easily set up the parent child connection. In order to create all the colliders yo can use the ragdoll wizard. I used this successfully for a similar problem in my project and even on iOS the additional colliders (IsTrigger = true) don't decrease the performance.