Legacy GM Check for collision between two other objects

D

DIYDamian

Guest
Hello. Is it possible to have an object check for collision between two other objects and have that collision affect itself?

The way how I'd use it is simple. I have a camera object that snaps to the player's position based on an 800x608 grid. I want it to pause any movement when the player is colliding with the object objCameraDisabler. As long as the player is colliding with that object, the camera doesn't snap to the player's position.

Here is the code. (This is in the Step Event btw)
Code:
///Move Camera

//Change position variables only if player exists
if (instance_exists(player) == true) {

    camToX = player.x
    camToY = player.y

}

//Move the camera
view_xview = (((floor(camToX/800)*800)+view_xview)/2)+random_range(-global.camShake, global.camShake);
if (camToY>0 && camToY<=room_height) {
    view_yview = (((floor(camToY/608)*608)+view_yview)/2)+random_range(-global.camShake, global.camShake);
}

//Shake Easing
global.camShake = global.camShake * 0.9
I know I'd have to do something in the code below "Change position variables only if player exists" to get the result I'm wanting, but what do I do?


tl;dr: How can I get the camera object to only perform a certain action if the objects player and objCameraDisabler aren't colliding?
 
Have 'player' containing a variable that it checks for - if they're colliding then its switched to 'on' (true) and the camera doesn't respond. When they're not in collision it's set to 'off' (false) and the camera will respond. The player object will need to be testing for collisions with objCameraDisabler, and set this variable accordingly. Then the camera object accesses the object 'player' collision variable:

if instance_exists(player) && !player.collision
//// player 'collision' is taken to be false. Note - you don't need the "== true" part for "if player exists". As the ! before 'player.collision' shows, it can be used to check for a variable, or condition, being false. Without ! they are tested as to whether they are true.
{do camera stuff}
else
/// player doesn't exist, or 'player.collision' is found to be true (since it's either true / false - and the "if false" has returned false, meaning it's true...)
{don't do camera stuff}
 
Last edited:
Top