Smooth way to associate objects?

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!

    I'm making a game where there are some dark places, but I'd like the player and certain enemies to be able to light it up. For this I need a smooth way to associate a "light object" (an active object) to every enemy or fireball. Please note that the darkness/light thing is not a problem (I've managed it with an extra layer and some MMF2 HWA settings), but I don't know how to do the active object association efficiently and with nice code.

    Thankful for any help!

  • Perhaps something like this, don't know if it works.

    use the foreach object and check distances between each enemy and each light

    Always (or however often you want to check)
    -start foreach loop "lights" for object lights


    onloop "lights" for object lights
    -start foreach loop "enemies" for object enemies


    onloop "enemies" for object enemies
    + Compare 2 general values
    Sqr((X( "enemy" )-X( "light" )) pow 2+(Y( "enemy" )-Y( "light" )) pow 2)< 300 (or distance you want)
    +flag enemy object flag 0 = off

    -add 1 to light alt value A
    + toggle enemy flag 0


    onloop "enemies" for object enemies
    + Compare 2 general values
    Sqr((X( "enemy" )-X( "light" )) pow 2+(Y( "enemy" )-Y( "light" )) pow 2)>= 300 (or distance you want)
    +flag enemy object flag 0 = on

    -subtract 1 from light alt value A
    + toggle enemy flag 0


    light alt value A > 0
    -turn lights on

    light alt value A <=0
    -turn lights off

  • The easiest way is to make sure you have the same number of both objects, and then do:
    Always: Set position of light to 0,0 from enemies.

    MMF will match one to each.

    Please login to see this picture.

Participate now!

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