Jump to content


Photo

A very basic targeting system


  • Please log in to reply
4 replies to this topic

#1 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 207 posts
  • Version:GM:Studio

Posted 17 June 2012 - 07:09 AM

So I was working on a game where one enemy moves from one side of the screen to the other, if there is a player in its path, it will walk towards it and attack it. I've achieved that using melee but I had trouble with range. What I had down here sorta does work, because the object does attack at a range while its passing by the only problem is that it doesn't stop. Another question was about the targeting system, I just need something basic that will target 1 out of a possible 11 objects that will be on the screen at a time. The way it currently is, it only targets the object because im using obj.x/y . But I just needed help to make this target the nearest enemy it encounters and also to make range stop and attack. Heres the code that I have so far

if(point_distance(player.x, player.y, x, y) <= 75) // detecting range
{
    if(auto_attack == true && point_distance(player.x, player.y, x, y) <= 50) // attack range
    {   //just for testing
        auto_attack = false;
        alarm[0] = 60;
        player.hitpoints -= 150;
    }
    else if(point_distance(player.x, player.y, x, y) <= 50)  //this is the issue, wanted it to move to its max attack range then stop and attack.
    {
        move_towards_point(player.x + 20,player.y, 3)
    }
}
else
{
    move_towards_point(ds_queue_dequeue(move), y, 3)    //moves to destination if no enemy was encountered.
}



  • 0

#2 pqp239

pqp239

    GMC Member

  • GMC Member
  • 105 posts
  • Version:GM:HTML5

Posted 17 June 2012 - 10:15 AM

else if(point_distance(player.x, player.y, x, y) <= 50)  //this is the issue, wanted it to move to its max attack range then stop and attack.
{
     move_towards_point(player.x + 20,player.y, 3)
}

Could you clarify a little bit more about your problem with movement? I'm not sure I quite understand what the problem is there.

For targeting, (again im not fully sure what you're saying) you could do something like this.

in the object to be target have a variable such as:
number=1;
and use a different number for each one. Then check for the nearest instance and then check for instance_nearest.number and what not and have it target said instance until it is out of range again.

So, with the targeting object have it set a variable to true if its targeting and false if its not. So that way it will only attack one specific object.

Sorry if that wasn't very clear. There are probably much better ways than what i just thought of jsut now.
  • 1

#3 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 207 posts
  • Version:GM:Studio

Posted 17 June 2012 - 05:26 PM

What happens is that the object would walk right by the enemy without stopping. But it would still attack as it was passing by, the issue im having is that it wont stop.
  • 0

#4 pqp239

pqp239

    GMC Member

  • GMC Member
  • 105 posts
  • Version:GM:HTML5

Posted 17 June 2012 - 07:26 PM

What happens is that the object would walk right by the enemy without stopping. But it would still attack as it was passing by, the issue im having is that it wont stop.

Oh, I think I understand now. Well I think your problem is this:

move_towards_point(player.x + 20,player.y, 3)

Its always going to move to to 20 places ahead of the enemy. This would only work in one direction and I'm assuming that is what your problem is? Half the time it works like planned then the other half it doesn't?
  • 0

#5 Subjugater247

Subjugater247

    GMC Member

  • GMC Member
  • 207 posts
  • Version:GM:Studio

Posted 18 June 2012 - 01:04 AM

the twenty was just to position itself right next to the enemy is was heading towards. but the problem does lie somewhere in that statement because that was the part that would have the object move towards the enemy
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users