putty174
putty174

Reputation: 315

Collision/Trigger detection between two remote objects

Is it possible to have a script in a GameEngine script and have it check for collisions between two remote objects that are not connected to the GameEngine script, via Update() or OnTriggerStay()/OnColliderStay()?

My plan for this script is to detect situations such as putting out room that is on fire. My original plan was to have a collider around this room checking for fire particles, and if there are no more particles, the fire is out. If you have a better suggestion, please let me know.

Upvotes: 0

Views: 248

Answers (1)

Dinal24
Dinal24

Reputation: 3192

I assume you are referring with linear motion. If so Ray Casting is the solution. Ray Casting is forming a line or vector from a specific point to another point in a 3D plane. The purpose of the ray (vector) is to determine if it intersects with any colliders or other game objects.

It can be simply used like,

void Update() {
    Vector3 fwd = transform.TransformDirection(Vector3.forward);

    // parameters are origin, direction and length of the ray. 
    if (Physics.Raycast(transform.position, fwd, 10)){ 
        print("There is something in front of the object!");
    }

}

You can find more references and tutorials on the internet. Try Unity official tutorial on Raycasting

Upvotes: 1

Related Questions