I'm having trouble with projectile targeting

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
__________________ Games projectiles ___________________
  • I want to make it so an object will target the nearest object, for multiple reasons, be it homing, dodging, or aiming. but construct likes to group events and I don't know how to undo that

    lets say I have objects a,b,c and targets 1,2,3. objects abc are all the same type, 123 are also all the same type

    a 1

    b 2

    c 3

    ideally a targets 1, b targets 2, and c targets 3, since that is the closest to each one. but instead a,b, and c all target 3 because it is the closest target of a type to an object of a type.

    Can I fix this somehow? maybe a way to make events that run for every single object of a type and ignore all other instances of that object

    currently I'm working with "pick nearest to enemy.x, enemy.y" which is causing the problem

    Tagged:

  • ok, multiple spaces don't work here, but it was meant to look like this

    a . . 1

    b . . 2

    c. . 3

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmmm... Depends. If you only plan to have 1 projectile towards 1 target at a time. You could apply an instance variable to the targets

    So it would be like

    Target instance variable set as a Boolean

    Istargeted?

    So when bullet spawns pick closests target with IsTargeted? false. Set bullet angle towards that target and set that targets instance variable to IsTargeted? True Then when the next projectile is spawned it should in theory pick the next closest.

    Then you can set it so when the projectile hits the target you can swap IsTargeted? To false

    If you want to be able to shoot multiple projectiles at a time towards multiple objects. It's a tad different. You may be able to utilize the objects ID. I can throw together an example tomorrow once I get off work.

  • construct.net/en/free-online-games/asteroids-game-63469/play

    this is the game, reload the game until you see the green bullets and select them (there are only 4 base weapons it shouldn't take too long)

    that is a much older version of the game but the current version I'm working with has the same problem. Instead the bullets all seek the nearest object to the mouse, which isn't really what I want but works as a substitute. instead I want them all to target independently, and whichever object is closest to each bullet

  • I solved it :), just needed "repeat for each"

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