Some help on an Attract/Repel attribute
JeppeTarp
Member Posts: 16
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
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
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
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
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.
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.