Some help on an Attract/Repel attribute

JeppeTarpJeppeTarp Member Posts: 16
edited November -1 in Working with GS (Mac)
Hey, so I'm busy creating my first game, graphics are pretty much done. Now I've encountered a few problems, as I'm not yet great at programming with GS.

My problem is: I want several IDENTICAL actors in the map, when I click one of them I want all of the others to accelerate toward that actor. If I F-click the actor all the others will be repelled from it - accelerate away.

The hard thing is, I need all actors to have this option, so if I have 10x of actor1 in the map, either one of them can be used as "the attractor" and "the repeller"

Thanks :)

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Try this:

    Create some game attributes:
    1) game.attract (boolean)
    2) game.repel (boolean)
    3) game.targetX
    4) game.targetY

    In the attract actor:

    create self.ImTheTarget (boolean)

    when touch is pressed
    ----change attribute self.ImTheTarget to 1

    new rule: when self.ImTheTarget is true
    -----change game.targetX to self.position.X
    -----change game.targetY to self.position.Y
    -----change game.attract to 1

    Then in the actors that move to the target:
    -----when game.attract is true
    -----accelerate towards (or try move to) game.targetX, game.targetY

    For repel you will do the same sort of thing accept you cannot use accelerate towards. You need to use this instead:

    when game.repel is true
    accelerate angle(to scene): (vectorToangle(game.targetX-self.position.X, game.targetY-self.targetY)+180
  • JeppeTarpJeppeTarp Member Posts: 16
    Thanks a bunch! That almost worked like a dream! The only problem I have now is that the "attractor" and the "follower" need to basically be the same actor (basically my map consists only of actor1). So how can I configure it so when my mouse clicks one of these actors, only the one that overlaps/collides with mouse XY changes attribute to game.imthetarget 1?

    Do I need to make say 100 identical actors with each their own imthetarget1, imthetarget2, imthetarget3, attributes etc.? Or can it be done with 1 actor? - Hope you get my point

    Is there a way I can rep. you or something for helping? Thanks a bunch man
  • MagoNicolasMagoNicolas Member, PRO Posts: 2,090
    It can be done with one actor.
    You create a Integer Attribute in that Actor Called something like: My number
    And Then you create rules like:
    if My number = 1 then: something
    If My number = 2 Then: other thing.
    etc.

    Then You drop the same actor 100 times in the Scene (Or n numbers you need) And Double click them, then just change the Attribute (Nothing more) You don't need to click the lock for that.

    Cheers.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    JeppeTarp said:
    Thanks a bunch! That almost worked like a dream! The only problem I have now is that the "attractor" and the "follower" need to basically be the same actor (basically my map consists only of actor1). So how can I configure it so when my mouse clicks one of these actors, only the one that overlaps/collides with mouse XY changes attribute to game.imthetarget 1?

    Do I need to make say 100 identical actors with each their own imthetarget1, imthetarget2, imthetarget3, attributes etc.? Or can it be done with 1 actor? - Hope you get my point

    Is there a way I can rep. you or something for helping? Thanks a bunch man

    No the way scitunes wrote it should work for only the one clicked.
    Add the the touch is pressed rule an Otherwise that changes self.imthetarget back to 0

    And an otherwise in the imthetarget rule that changes game.attract back to 0

    That will make the attraction stop when touch is released and allow the game.targetx and game.targety attributes to be changed again by a different touch.
Sign In or Register to comment.