Left & Right Movement
Hi Everyone,
I am working on a side scroller platform game and am struggling with enemies movement back and forth - I AM ABLE TO MOVE THEM BACK AND FORTH, It's just that they are all moving back and forth from an X coordinate relative to the seen as a whole and NOT from where they are sitting in the game. I have about 20 enemies i want to move back and forth and they all move to 100px (the very beginning of the scene) instead of 100 left or right from where they are positioned in the scene. Any advice on how to fix this? I imagine some sort of attribute to locate their starting point and move 100 px from there but am unsure how to accomplish this. Any help would be greatly appreciated!!
Thanks, Josh
I am working on a side scroller platform game and am struggling with enemies movement back and forth - I AM ABLE TO MOVE THEM BACK AND FORTH, It's just that they are all moving back and forth from an X coordinate relative to the seen as a whole and NOT from where they are sitting in the game. I have about 20 enemies i want to move back and forth and they all move to 100px (the very beginning of the scene) instead of 100 left or right from where they are positioned in the scene. Any advice on how to fix this? I imagine some sort of attribute to locate their starting point and move 100 px from there but am unsure how to accomplish this. Any help would be greatly appreciated!!
Thanks, Josh
Best Answer
-
RThurman Posts: 2,881
The suggestion I gave will move each actor relative to its own unique starting position on the scene. Give it a try!
Edit: Here is what it looks like using the cookbook behaviors you referenced above:
Change Attribute: self.myStartX To: self.Position.X
When attribute self.position.x is less than or equal to self.myStartX
--Interpolate self.position.x to self.myStartX+380 Duration 1
Otherwise
--When attribute self.position.x is Greater than or equal to self.myStartX+380
----Interpolate self.position.x to self.myStartX Duration 1
Answers
@jmagness
Hi Josh, whatever your chosen method of moving your actors, it's sounding like you have "Relative to" - in the Behavior - set to "actor". Change this to "scene" and hopefully you're good to go.
http://cookbook.gamesalad.com/question/4d9e12395e76e160530003fd
The problem is you have to give each actor you want to move back and forth a starting and stoping x value. I have 2 dozen actors across a 2500px screen. I would much rather say move back and forth from where you STARTED in the scene not a specific x coordinate.
I tried making an attribute and changing it to the actors self.position x, but it doesn't seem to be working either?
OK, I see; try something like:
Rule When attribute self.position.x = 100
Interpolate self.position.x to 380
----no otherwise
Rule: When attribute self.position.x = 380
Interpolate self.position.x to 100
See if that works out for you.
I don't want to have to make 30 actors with different start and stop values.
Change Attribute: myStartX To: self.Position.X
Change Attribute: myStartY To: self.Position.Y
Then refer to myStartX and myStartY in your movement behaviors.
1. Make an attribute for your character, I called mine startpositionx
2. Constrain self.startpoitionx to self.position.X
3. Rule > if Attribute self.Position.X is less than or equal to self.startpositionx-100+(self.Size.Width /2) Change attribute self.Motion.Linear Velocity X to 80
4. Rule > if Attribute self.Position.X is greater than or equal to self.startpositionx+100-(self.Size.Width /2) Change attribute self.Motion.Linear Velocity X to -80
You can change the 100 to make him go fourth or closer, and the 80's to make your actor speed up or slow down!
Thanks Everyone!