GameMaker: Studio

GameMaker: Studio

View Stats:
Burusagi Oct 14, 2016 @ 8:29am
Patrolling enemy.
Anyone have any points in how to code one? I'm thinking of simply making an obj_enemy with a Speed variable and then changing it's x-position every Step, and then somehow use a Timer to turn a positive Speed variable into a negative one - wouldn't that make it turn the other direction?
< >
Showing 1-9 of 9 comments
sitebender Oct 14, 2016 @ 8:37am 
if ( LR )
{
x -= spd
if ( x < xstart - 100)
{
LR = !LR
}
}else
{
x += spd
if ( x > xstart + 100)
{
LR = !LR
}
}

// this is as simple a code as I can provide.
Diveyoc Oct 14, 2016 @ 9:01am 
I'm still experimenting myself, but this seems like a nice command. By selecting false for the last symbol, enemy checks for solid objects and will try to avoid them.

mp_potential_step(obj_player.x,obj_player.y, 2, false);

And,
motion_set(choose(0, 45, 90, 135, 180, 225, 270, 315), 2);

Will make enemy choose a random direction.
Burusagi Oct 14, 2016 @ 9:18am 
Originally posted by sitebender:
if ( LR )
{
x -= spd
if ( x < xstart - 100)
{
LR = !LR
}
}else
{
x += spd
if ( x > xstart + 100)
{
LR = !LR
}
}

// this is as simple a code as I can provide.


Don't take this the wrong way, as I definitely appreciate the reply, but any chance you could elaborate? Because just copy/paste'ing code I don't really learn! :3
Curious Duck Oct 14, 2016 @ 9:33am 
https://youtu.be/LYAskDJ75Ss
https://youtu.be/DG1L2Fbrhlg
https://youtu.be/pNg9axObUbk
Without specific which type of game it's for (top down, platform etc) I've posted the videos above in an open response of helping.
Burusagi Oct 14, 2016 @ 9:37am 
Oh, it's a basic 2D sidescroller, so it basically just needs to walk left and right.
Curious Duck Oct 14, 2016 @ 9:42am 
Then look at this
https://youtu.be/S-F51V01zXM
sitebender Oct 14, 2016 @ 9:59am 
Originally posted by Alcohol Fueled Brewtality:
Originally posted by sitebender:
if ( LR )
{
x -= spd
if ( x < xstart - 100)
{
LR = !LR
}
}else
{
x += spd
if ( x > xstart + 100)
{
LR = !LR
}
}

// this is as simple a code as I can provide.


Don't take this the wrong way, as I definitely appreciate the reply, but any chance you could elaborate? Because just copy/paste'ing code I don't really learn! :3

LR is left right. spd is the speed variable. xstart is where the object starts.

You need to set the spd and LR in the create event.
Burusagi Oct 14, 2016 @ 2:56pm 
Originally posted by Matt the Duck:
Then look at this
https://youtu.be/S-F51V01zXM

I can't seem to get that to work. The enemy won't move.

Whenever I try and use my created scripts, the text remains golden yellow and not blue as in the video. Is there something I have to do to "enable" my scripts first?
Last edited by Burusagi; Oct 14, 2016 @ 3:19pm
Diveyoc Oct 14, 2016 @ 4:11pm 
You have to change the font color in global settings to make them come up blue, otherwise they will be yellow by standard default.
< >
Showing 1-9 of 9 comments
Per page: 1530 50

Date Posted: Oct 14, 2016 @ 8:29am
Posts: 9