Jump to content


Photo

tower defense targetting


  • Please log in to reply
9 replies to this topic

#1 gamearium

gamearium

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 27 June 2012 - 04:57 AM

how do i get my towers to target the enemy closest to the exit? please and thank you
  • 0

#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 27 June 2012 - 05:03 AM

If following a path, I got the code in my tower defense tutorial. in my tools page
  • 0

#3 gamearium

gamearium

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 27 June 2012 - 05:32 AM

its not a set path, its mp_grid and the path can change. i dont think i can use instance_furthest_along.
  • 0

#4 gamearium

gamearium

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 27 June 2012 - 06:32 AM

can i get the tower to target the object with the least distance to the exit?
  • 0

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 27 June 2012 - 06:38 AM

its not a set path, its mp_grid and the path can change. i dont think i can use instance_furthest_along.


mp_grid returns a path, you did not use path_start with it?

You can mod instance_furthest_along to do a point_distance from x,y to exit.x and exit.y instead of looking at the path_position. But that is not truly if it's closest to be done as it may walk close to the exit while still be a long way from getting there. Like when you tile your turrets to make the kreepers zig zag like the original TD game
  • 0

#6 gamearium

gamearium

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 27 June 2012 - 07:16 AM

yes, path_start, but when a new tower is laid a new path starts.
  • 0

#7 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 27 June 2012 - 02:39 PM

do a path_get_length to get the pixel length after a new path

m_PLen = path_get_length(newpath);

now you can implement a path_point_distance like this
//123 - ((0->1) *123) = 123 - (0->123) = 123->0
return m_PLen -(path_position*m_PLen);
  • 0

#8 lordvtp

lordvtp

    GMC Member

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

Posted 27 June 2012 - 09:45 PM

or just do this

target = instance_furthest(exit.x,exit.y,enemy)
:thumbsup:
  • 0

#9 gamearium

gamearium

    GMC Member

  • New Member
  • 5 posts
  • Version:GM:Studio

Posted 29 June 2012 - 04:23 AM

i have been using path_get _length, but you lost me with that equation. is that to tell the tower to shoot at the shortest length?
  • 0

#10 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14391 posts
  • Version:GM:Studio

Posted 29 June 2012 - 04:28 AM

the length left.... the equation can be used as a replacement of the original path_position equation in my script.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users