I want to have a character made out of cubes and affected by gravity to be destroyed per cube when I drop a ball on it with a script to destroy everything it touches. I want to let the character move too.
I have a character made out of different cubes parented to an empty gameobject with a rigidbody. all the cubes have a box collider. I have given all the cubes a kinematic rigidbody which let the cubes be destroyed seperately if I toggle off the gravity of the empty game object. But when I toggle it on my character falls through the floor.
Is there a way to not let the character fall through the floor?
Thanks in advance.
Just really quick, the reason he is falling through the floor is the kinematics. I will give you an answer with proper documentation and ways to understand or fix this problem.
@Vedang202 Array/list is the most efficient way i can think of. Using Overlap sphere is way way expensive. N i don't understand what you mean by detecting through code itself! IF you use array/list, they are part of code as well!
Ok, I did some testing and I think I found a way to answer your question. When force is applied to a kinematic object, like a player falling due to gravity, the kinematic object ( to put it simply) can be interacted with, but does not interact with the world. That might be confusing, here’s a link to the manual : Unity - Manual: Rigidbody component reference
You will just want to look at isKinematic. Basically it’s used for interacting with objects with collision, but without moving them (Like the doc says, moving platforms)
You still have the question about making your character NOT fall through the floor, and I also understand where your need for kinematic rigidbody comes from, so I will suggest one of two things.
Try to raycast collisions (This is kind of difficult and sometimes not too reliable)
Make a gameobject for the feet of your player, position it correctly and then take off the mesh renderer and set its box collider to isTrigger. Then you can make a basic script for detecting collisions with that. ( I have a script like this, so if you can’t figure that out I can help you there too)
Maybe this helped or it was just confusing, either way hope you can figure it out!
I tried to do the second one but I am stuck at the script part. I made a script using OnCollisionEnter and OnCollisionExit to check if the box hits the ground or not. I checked if it worked with a Debug.Log message but I did not recieve a message when the boxes hit the ground. I am also thinking of letting the character stop by activating the Is Kinamatic of the empty gameobject but i don't know if that is going to have consequences for if I want to move it.
Just add a capsule collider and make sure that the ground has a box collider
Thank you for your response, but it doesn't seem to be working for me. I am dragging the files from my folder into the assets window yet there is no save window popping up. Do you know if the feature you're talking about is available on Unity 5.6? PS. I also tried dragging into the scene window as well to see if that was what you meant.
Just really quick, the reason he is falling through the floor is the kinematics. I will give you an answer with proper documentation and ways to understand or fix this problem.
– SeaLeviathan@Vedang202 Array/list is the most efficient way i can think of. Using Overlap sphere is way way expensive. N i don't understand what you mean by detecting through code itself! IF you use array/list, they are part of code as well!
– bhavinbhai2707