Left & Right Movement

jmagnessjmagness Member Posts: 9
edited June 2012 in Working with GS (Mac)
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

Best Answer

  • RThurmanRThurman Posts: 2,881
    edited June 2012 Accepted Answer
    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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2012

    @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.
  • jmagnessjmagness Member Posts: 9
    No that is not the case at all. I referenced this tutorial to make an object move back and forth:

    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?

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    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.
  • jmagnessjmagness Member Posts: 9
    That would work, however it is STILL making move relative to a location in the SCENE not to where i have placed the actor in the scene. If i have an actor at the end (around 1500 in) it will travel all the way to the beginning (100) and then bounce back and forth between 100 and 380.

    I don't want to have to make 30 actors with different start and stop values.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Give the actor two attributes (type = real) name them myStartX and myStartY. Then use two change attributes behaviors to record the starting position of each actor when the scene begins:
    Change Attribute: myStartX To: self.Position.X
    Change Attribute: myStartY To: self.Position.Y

    Then refer to myStartX and myStartY in your movement behaviors.
  • jmagnessjmagness Member Posts: 9
    Again, I can't make this any clearer, all of these suggestions work, FOR MOVING THE ACTOR RELATIVE TO THE SCENE, I need to move the actor relative to itself...
  • jmagnessjmagness Member Posts: 9
    Ok, so none of these were exactly right but everyone helped and I did manage to get it working the way I would like! So thanks to everyones input and help we now have an answer!

    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!

Sign In or Register to comment.