I have two questions. One regarding Collision and the other regarding physics.
1.) Is it possible to add 3 or 4 box colliders to one mesh? My mesh consists of 3 boxes that are all connected, so it would be wasteful to attach a mesh collider to it because it will be colliding to similar meshes of the same shape.
2.) When dealing with collision, when two hit each other they start jumbling in space because I set gravity off. I want them to collide, but not move when they hit each other. Would I add a check like this:
function OnCollisionEnter {
Collision.other.tranform.position = /*...position when collision...*/;
Transform.position = /*...position when collision...*/;
}
If that would work, I will have no problem findind ithey collide…
Thanks again
Btw, do I have to add rigid bodies for them to collide? As they don’t collide when a rigid body isn’t attached to them.
Your first question is a yes. You can parent objects with colliders to your object and disable their renderers. Probably other, more efficient ways too.
I don’t quite understand what you are trying to do. The best way to have complex objets that move with physics and collide realisticly is to have an object with your complex mesh and a rigidbody that parents several children with colliders.
I don’t understand the second question. You can make objects not bounce by applying a physics material with bouncyness of 0. To make a physics material select it from the create menu in the assets pane.
The politically correct script hack for this would be:
function OnCollisionEnter ()
{
rigidbody.AddForce(-rigidbody.velocity, ForceMode.VelocityChange);
rigidbody.AddTorque(-rigidbody.angularVelocity, ForceMode.VelocityChange);
}
What I’m trying to ask is, how can I have the two collide with having any physics? Basically I just want them to collide and not move at all when they do collide. But in order for them to collide I had to add a rigid body to them, or is there another way for the collision to respond without adding a rigid body?
I’ll try your script, but I’m at school right now, so I don’t have access to Unity.
If you only want to get notified when the objects intersect each other, you can use triggers. Just enable the isTrigger checkbox on the collider and replace OnCollisionEnter with OnTriggerEnter.
Well, I just realized that “is Kinematic” is the effect that I want. But unfortunately, if I enable “is Kinematic” on both meshes, they don’t collide >.<
So close, yet so far :p…
I have 3D pieces of a puzzle, and I want the user to be able to move them together to form the picture. I’ve got the movement, highlighting is mainly working, and collision doesn’t work unless I add a rigidbody to them. Som the only way to get rid of physics, is either:
1.) not use a rigid body - but then they don’t collide
2.) Us the triggers, but I’m not sure how to make them collide when using the is Trigger…
Is “pice in others” actual code? Or is that psuedo? Also, if it does collide, how would I stop it? Have a variable holding its position it collided then, set its current position to where it was when it did collide?
Yes that is real code. What it does is do the stuff in between the {} after for() to each object in others. It creates a temporary variable named “pice” to link to each object.
I would make it so that when a pice is selected and you press a arrow key it will move one space. If it collides it would move back. You could do it like this:
This would snap if it collided while in mid move but that should never happen if it is set up right. You have to set selected from an other script or merge your selection script with this one.