• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker (SOLVED) "Thicker" collision_line OR alternative?

Hello GML gurus.

Background:
I've got a state based turret coming up from the floor when the player object is within range. When walking even closer it shoots at the player. When stepping away it stops shooting and when walking farther away, it drops back down into the floor.
This all works well except for one thing that's driving me crazy.

I'm checking if the player is in range with

Code:
if (state == turretstate.inactive) {
    #region INACTIVE


sprite_index = sprTurret;
image_speed = 0;
image_index = 0;
    
    //Transition trigger - raise the turret
    if (collision_line(x-200, y, x+200, y, objPlayer, false, false)){

        state = turretstate.goingup;

    }
... and this is what I need help with:
Code:
    //Transition trigger - raise the turret
    if (collision_line(x-200, y, x+200, y, objPlayer, false, false)){
If the player jumps while within reach the turret goes down. In a way I guess that mean it's working correctly but I want the collision line to be... thicker, so to speak.
I want the player to be in range even when airborn and when directly over the turret.

The things I've tried so far is variations of:
Code:
collision_line
point_distance
collision_ellipse //although I'd rather not use this one
... but without making it work. I'm sure it's possible to fix it with one or more of the above (or something completely different) I just don't know how to.

All help will be greatly appreciated!
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Since your collision line is completely horizontal, a thicker collision_line would be just collision_rectangle.
 
if abs(x-objPlayer.x) < 200 && abs(y-objPlayer.y) < 64 (or whatever your jump height is)
The player can actually fly for short periods but all it takes to break out is a jump.
Well.. all it took. YellowAfterlife's way worked perfectly.
I'll look into your code as well, it will teach me new things for sure. Thank you.
 
Top