how to detect if box collider is all inside another box collider unity
- User
how to detect if box collider is all inside another box collider unity
- Assistant
- User
Can it be posible to know this with the information provided in oncollisionenter method?
- Assistant
- User
I am creating a starategy game, a have farms and windmill with square shape each one of 4x4, when a windmill is added it improves the productivity of the farms in a 12x12 radio, how can i achieve this, so when a farm is added it also icreases its productivity and when the windmill is destroyed all the productivity decreases
- Assistant
- User
The farm also needs a collider?
- Assistant
No, the farm does not necessarily need a collider if you're only using the windmill's trigger collider to detect the presence of farms. When the windmill's trigger collider overlaps with another object, Unity's physics engine will take care of calling
OnTriggerEnterorOnTriggerExiton the object with the script attached to the trigger collider (in this case, the windmill).However, it's common practice to also attach a collider to the farms to act as a way to detect interactions in both directions, as well as for other potential gameplay interactions (such as unit pathfinding or selection). If the farms also have colliders, you can easier detect when they enter or leave the windmill's area of effect without relying on the position checks. This is helpful especially if you want farms to trigger certain actions themselves when entering or exiting the range of a windmill.
- User
the collider in the windmill needs to be set to trigger in the inspector?
- Assistant
Yes, the collider on the windmill that you're using to detect the presence of farms should be set as a trigger in the Unity Inspector. When a collider is marked as a trigger (
isTriggerproperty is set to true), it doesn't behave as a solid object that responds to physics collisions. Instead, it can detect when other colliders enter, stay, or exit its boundaries without causing a physical response in terms of forces being applied to either object.To set a collider as a trigger in Unity:
- Click on the windmill GameObject in the Unity Hierarchy.
- In the Inspector panel, ensure it has a
BoxCollidercomponent. - In the component properties, check the box labeled "Is Trigger."
- User
on trigger enter is not being called
- Assistant
- User
I dont want to use rigidbodies
- Assistant
- User
My objects also are not static
- Assistant