1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

[SOLVED]Adding a range that follows the player

Discussion in 'Programming' started by MattD227, Aug 23, 2019.

  1. MattD227

    MattD227 Member

    Joined:
    Aug 23, 2019
    Posts:
    4
    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: Aug 23, 2019
  2. spoonsinbunnies

    spoonsinbunnies Member

    Joined:
    Aug 24, 2018
    Posts:
    115
    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.
     
    MattD227 likes this.
  3. 2Dcube

    2Dcube Member

    Joined:
    Jun 23, 2016
    Posts:
    384
    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.
     
  4. MattD227

    MattD227 Member

    Joined:
    Aug 23, 2019
    Posts:
    4
    After trying this I got it to work, I was putting that code under the wrong type of event, thank you for that
     
  5. MattD227

    MattD227 Member

    Joined:
    Aug 23, 2019
    Posts:
    4
    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
     
  6. MattD227

    MattD227 Member

    Joined:
    Aug 23, 2019
    Posts:
    4
    can someone tell me how I would put a thread as solved? my issue was cleared up
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice