Nearest instance?

0 favourites
  • A .capx would be nice... they are always very informative!

    You're lucky I managed to do this at work! It's here. Hope this helps you and anyone else!

    The block points itself to the nearest purple enemy. You can see the collision box!

    Edit: Here's an exported version if you just want to see it in action!

    Edit2: Updated links to take out the collision test. Now they only use Ashley's method!

  • Don't use invisible collision objects! It could make it run much slower than the loop I described using events only.

    Remember the way condition works already has a built-in 'for each'. So an event reading 'A overlaps B' means 'For each A: test if overlaps B, and remember both instances if so'. Therefore, using an object to test overlap of nearby objects still tests every single instance in the game. Worse, collision checks can be much slower than just measuring the distance. So I would strongly recommend you do not use a big overlapping sprite - just use something based on the events I posted, it's the fastest and simplest way.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Don't use invisible collision objects! It could make it run much slower than the loop I described using events only.

    Remember the way condition works already has a built-in 'for each'. So an event reading 'A overlaps B' means 'For each A: test if overlaps B, and remember both instances if so'. Therefore, using an object to test overlap of nearby objects still tests every single instance in the game. Worse, collision checks can be much slower than just measuring the distance. So I would strongly recommend you do not use a big overlapping sprite - just use something based on the events I posted, it's the fastest and simplest way.

    Whoops sorry about that! Thanks for that Ashley. A forgot to think about how the collision works :/ I've updated the links to take out the collision square! Just uses your method now... <img src="smileys/smiley5.gif" border="0" align="middle" />

  • It seems the .capx still uses a collision box?

    EDIT: I removed all the code that checks for collision. It runs perfectly and at 59fps when there are many squares to check. So it seems OK.

    Next step. What happens when I have multiple instances of the object which checks as well?

  • It seems the .capx still uses a collision box?

    EDIT: I removed all the code that checks for collision. It runs perfectly and at 59fps when there are many squares to check. So it seems OK.

    Next step. What happens when I have multiple instances of the object which checks as well?

    Don't know what happened with the link DropBox didn't update the file properly I think it *should* be the new version now...

    Is this what you mean?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)