How to make a object that follows player?

U

UglyDog

Guest
I can't seem to find a sollution to how to make an object around the player for a certain time (a bubble around player that last for 2 secs for example) when I click the right mouse button and make it follow the player.

Probably very simple thing but not a simple thing for me.

I'm using GML.

Thank you very much for all the answers!
 

TheouAegis

Member
Well, depends on how you want to actually handle things.

Player's Step Event:
if mouse_button_pressed(mb_right) && can_bubble
{
alarm[10] = room_speed * 2;
bubble = instance_create(x,y,obj_bubble);
can_bubble = false;
}


Player's Create Event:
bubble = noone;
can_bubble = true;


Player's Alarm[10] Event:
with bubble
{
other.can_bubble = true;
instance_destroy();
}
bubble = noone;
 
U

UglyDog

Guest
It says: "Unknown function or script: mouse_button_pressed. But getting closer I think :)
 
U

UglyDog

Guest
Well, depends on how you want to actually handle things.

Player's Step Event:
if mouse_button_pressed(mb_right) && can_bubble
{
alarm[10] = room_speed * 2;
bubble = instance_create(x,y,obj_bubble);
can_bubble = false;
}


Player's Create Event:
bubble = noone;
can_bubble = true;


Player's Alarm[10] Event:
with bubble
{
other.can_bubble = true;
instance_destroy();
}
bubble = noone;

Oh yeah I just changed the "if mouse_button_pressed(mb_right) && can_bubble" to "if mouse_check_button_pressed(mb_right) && (can_bubble)"

Thank you for your time!
 
U

UglyDog

Guest
Hey I noticed that I can only do it once. Then it doesn't work anymore. Do I need somekind of "else" code in the end?
 

TheouAegis

Member
Can the bubble be destroyed prematurely? I kinda crippled the code if that happened.

Player's Alarm[10] Event:
with bubble instance_destroy();
bubble = noone;
can_bubble = true;

As long as can_bubble is true, you should be able to create another bubble.
 
Top