Calculating distance with multiple duplicate objects - Magnet behavior

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi all!

    Trying to work out how I can make this work properly. Going to have multiple duplicate objects created offscreen and floating upward towards the player. when the player gets close to one within 200 pixels I'd like all of the objects within that area look towards the player like a magnet. I got it sort of working, but I notice it only goes off from the last created object, so anything that floats past that was created earlier doesn't get triggered.

    How can I change the code so all duplicate objects are being checked for a distance of 200 px? Thanks for any advice!

  • The "Compare two general values" doesn't scope individual objects the same way as something like collisions or comparing an object's own alterable value (so it doesn't look for objects the same way)

    If you store the distance though of each object to the player as an alterable value, then you can check the value for each object:
    Please login to see this attachment.

    This will make the objects float towards the player if that individual object is <200 pixels away.

    This won't make the whole 'squad' of objects all nearby start floating towards the player (i.e. if some objects in the 'squad' are further than 200px then they won't move towards the player), but you could make it so any time an object starts flying towards the player it creates another (bigger and invisible) object. That's a little bit trickier to do, but here's one way of doing it that I hope makes sense:

    Please login to see this attachment. (The first frame will just make nearby objects float towards the player, the second frame does the 'squad' behaviour)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!