I have a situation where I have 1 particular object that needs to register a collision (ontrigger I guess) but no physics applied.
The problem is this object has to have physics with everything else.(hence can’t just have ontrigger)
So I am kind of confused
If I give it a collider it will get the physics yet if I don’t it won’t.
I wish to apply physics on a case by case basis but can’t see an easy way of doing this yet still have collisions.
Equally the colliding object doesn’t have a ‘trigger’ because it applies physics.
On other physics engines I’ve used you had the option that on collision ‘do something’ then return 0 for no physics action or 1 for physics to be applied. This was neat as you could do anything you wanted.
Any help appreciated
I’m not quite sure what exactly it is that you want to achieve (your post is a little confusing), but if you want to be able to detect collisions on a GameObject but you don’t want to have Physics applied to it, I would do the following:
Select the GameObject in question so it shows up in the inspector
In the Unity menue, go to Component/Physics/Rigidbody - this will add a rigidbody to your component
Modify the rigidbody until its size roughly fits the boundaries your GameObject
Select your model again and choose the Rigidbody-Component in the inspector. Turn off the Gravity and set any values which regard physics to zero
You’re now able to register collisions by using that rigidbody, but the gameObject still is not affected by gravity. As long as you do not apply any physics force to the GameObject, it should be unaffected by the physics system (moving it by translating is fine as it is no physics action).
That’s just my way of doing things, if your GameObject happens to be a character, you can apply a CharacterController instead of a Rigidbody, but the workflow is very similar.
I’m not sure, if I understand you right.
If your object is no rigidbody, then it should not be affected by forces or whatever “physics”. If you put the collider component on it and set the checkbox “isTrigger”, then it should work as a trigger.
Maybe you can give your game object a separate layer and then chose in the physics menu in Unity, which layers collide with other layers.
Edit >> Project Settings >> Physics
The problem is it’s progmatic i.e. I want to control the collision type to outcome.
I’ll explain what I am doing as it may help
I have a boomerang which is a kinetic rigid body.
It can hit other non-kinematic bodies i.e. apply physics etc. and push them around which is great.
It can hit the bomb; but I want the bomb ‘not’ to have physics applied but need to know if it collides.
The bomb though can’t just be a ‘trigger’ because it can collide with other non-kinematic and kinematic bodies and therefore apply physics.
So it’s kind of like a special case. I suppose I could move the bomb to a different layer when I don’t want it to be affected by the boomerang but that means the bomb won’t affect the other objects.
Erm, does that help? :-))))
exclude the collision between this two layers only
Now your bomb will collide with everything but the boomerang and the boomerang will collide with everything but the bomb.
To get the collision information between both:
duplicate the boomerang and make it a child of the original one in hierarchy
make the duplicate kinematic, put it in a third layer and let this layer only hit with the bomb layer
So you get a 2in1 boomerang. The visible part hits anything but bombs and has physical effect. The invisible part will go through anything, including bombs, but you will get the OnCollision or OnTrigger call when hitting bombs.
Thanks. I did think of rather messy solutions like yours. But as it seems probably the only way to achieve it I shall go with it
Your help is much appreciated!!!
It seems dirty, but it’s actually the way a lot of things are done in games.
Don’t go all purist on me. Whatever works.
Especially since it won’t add overhead (compared to specialized code to handle this one situation it’s pretty clean I would think and this is one of the reasons layers exist in the first place)
In essence if you tried to code it you would end up creating a specialized “layer” for the collisions you want, but you simply wouldn’t call it a layer.
Thanks so much for this! I’ve been trying to get this to work using various if statements with isKinematic and SetActive - nothing has worked, except for this. So thank you!