[SOLVED]Adding a range that follows the player

MattD227

Member
Hey guys, so I'm very new to GameMaker and don't fully understand GML yet. What I have right now is that the player will go to wherever you click on screen and I'm wanting to add a range around them that will follow the player.

I have a sprite made for the range, but I do not know the code needed to connect them to the player and I can't find a video online that can help me with this, can someone help me?

Also, this is my first time posting on here so I don't know what all would be needed, if someone would need to see the code for how the player then I will edit this to show that.
 
Last edited:
first you have to make an object that has the sprite you created, next you want its depth to be higher than the player sprite, if its not it may cover your player. After that its as simple as something like this in the step or end step event of the new object
x=player.x
y=player.y

keep in mind you have to change the word player to whatever you named your player object.
 

2Dcube

Member
What is a "range" ? Is it a radius around the player that shows how far you can walk each time?

If you want to simply draw it on screen as the same location as the player, you could do this in the Draw Event:
Code:
draw_sprite(sprRange, 0, x, y);

draw_self(); // this will draw the object itself (in this case the player object and its sprite that you have assigned)
The range is drawn first so it shows underneath the player, but you can switch the 2 lines around if you want to draw it on top.
 

MattD227

Member
first you have to make an object that has the sprite you created, next you want its depth to be higher than the player sprite, if its not it may cover your player. After that its as simple as something like this in the step or end step event of the new object
x=player.x
y=player.y

keep in mind you have to change the word player to whatever you named your player object.
After trying this I got it to work, I was putting that code under the wrong type of event, thank you for that
 

MattD227

Member
What is a "range" ? Is it a radius around the player that shows how far you can walk each time?

If you want to simply draw it on screen as the same location as the player, you could do this in the Draw Event:
Code:
draw_sprite(sprRange, 0, x, y);

draw_self(); // this will draw the object itself (in this case the player object and its sprite that you have assigned)
The range is drawn first so it shows underneath the player, but you can switch the 2 lines around if you want to draw it on top.
the range is going to be the players sight for seeing an enemy and then attacking them. Using the basic code from the others comment I was able to get it to do what I needed. Now I just need to get it so when the enemy spawns in they are able to move towards the player and do the same thing
 
Top