collision help

You define the object C variable when collides with it.
Like:
GML:
// in obj_a...
if place_meeting(x,y,obj_b)
{
    obj_c.variable = true;
}
 
Last edited:

Hypotakt

Member
Do you mean something like, Object B should check collisions with Object C, but Object A triggers the thing? A solution to this could be done with this:

-Object B-
GML:
//;; CREATE EVENT ;;

//BOOLEAN FOR COLLISION CHECK START
collision_trigger = false;

//OBJECT FOR THE COLLISION CHECK
collision_object = noone;
GML:
//;; STEP EVENT ;;

if(collision_trigger){
    if(collision_object != noone)
        
        //DO THE COLLISION CHECK
        collision_point( x, y, collision_object, false, true );
        
        //CLEAR THE VARIABLES
        collision_object = noone;
        collision_trigger = false;
    }
}
- Object A -
GML:
//;; CREATE EVENT ;;

//TRIGGER THE COLLISION WITH OBJECT_A AND OBJECT_B
collision_start = true;
GML:
//;; STEP EVENT ;;

if(collision_start){
    //GIVE OBJECT_B THE COLLISION DATA
    var instance_Object_B = instance_find(Object_B, 0);
    instance_Object_B.collision_object = instance_find(Object_C, 0);
    instance_Object_B.collision_trigger = true;
    
    //DEACTIVATE THE COLLISION TRIGGER
    collision_start = false;
}
You get the idea? Object B has some boolean check if the collision betwen B and C should trigger, and Object A gives the data for this, and sets the trigger bool for Object B to true :)

- cheers
 

Roldy

Member
Hello all
I have a question. How would i make an object A collision with object B affect Object
C?
I think you would have to provide more info depending on what sort of behavior you want.

But there could be several ways of doing so.

For instance in the A and B collision event you could set a variable in C.

GML:
// In the collision event for A and B
// Get the instance of object C you want to be effected and set a variable

instanceOfC.collisionOccuredBetweenAandB = true;

// Now C knows a collision happened and will process it in its next step event
Then in object C step event just check if that variable is set.

GML:
// Object C's step event

if (collisionOccuredBetweenAandB == true) {
   // Do stuff you want C to do

   // clear out the variable so you know you handled it
   collisionOccuredBetweenAandB = false;
}
Or instead of setting a variable call a user_event: https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/objects/generating events/event_user.html

GML:
// In the collision event for A and B
// Get the instance of object C and call a user_event

// make instanceOfC call user even zero
with(instanceOfC) {
  event_user(0);
}


// Now C's user event zero will be called which can make C react to the collision
There are countless other ways, but consider those two.


EDIT: Fixed my event_user example.
 
Last edited:

woods

Member
check for collision
if collision is true run script


would help alot if you showed what you are working with ;o)
 
Top