Moving an actor between points without it leaving a set area

ToecutterToecutter Member Posts: 19
edited June 2012 in Working with GS (Mac)
I want to move my actor vertically between one of three set points (each one above the other) and I can do this using the change attribute feature using self.position.Y+/-(amount in pixels) & pressing the arrow keys. However my actor can go beyond the 3 positions I want to use and I need some method to contain it. Using another actor to block it gives unexpected results. Is there any rule or attribute I can use to set a minimum & maximum range it can move between. Thank you

Best Answer

Answers

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

    Hi @Toecutter

    For setting minimum and maximum ranges, you use condition Rules: When Y < (---is less than) and When Y > (---is more than), then your change attribute, in each instance.

    But I'm thinking, as you've only got 3 set points, another way might be a bit more "watertight" perhaps?:

    In your Up button, put:

    When touch is pressed
    When scene.ActorMoving.Y = ---first set point Y coordinate
    Change attribute scene.ActorMoving.Y to ---second point y coordinate

    When scene.ActorMoving.Y = ---second set point Y coordinate
    Change attribute scene.ActorMoving.Y to ---third point y coordinate

    then in your down button, put:

    When touch is pressed
    When scene.ActorMoving.Y = ---third set point Y coordinate
    Change attribute scene.ActorMoving.Y to ---second point y coordinate

    When scene.ActorMoving.Y = ---second set point Y coordinate
    Change attribute scene.ActorMoving.Y to ---first point y coordinate
  • rotorrotor Member Posts: 25
    Alternatively, you could perhaps set a threshold to your destinations by setting a circular collider with a set size, when an actor 'touches' this area you interpolate the object to 'snap' to that point.
  • ToecutterToecutter Member Posts: 19
    My first effort was this:
    http://i1114.photobucket.com/albums/k539/toecutter78/GS.jpg
    This moved between 2 point just fine but I couldn't find how to add a point inbetween the minimum & maximum setting.

    @Gyroscope
    Thanks for the help but I don't quite understand (Sorry if this sounds stupid!).
    Getting lost with "When scene.ActorMoving.Y = ---first set point Y coordinate".
    Am I adding an attribute to the scene (I imagine a boolean as its a yes/no) for scene.ActorMoving. so it appears after the attribute when I select it in the rule box?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited June 2012

    Hi again @Toecutter

    If I'm understanding what you're after correctly, you've made your Rules overly-complex perhaps, with your self.upLimit etc., equation for instance. And if you just want your actor to jump to the positions, you don't need any Constrain Behaviors.

    My bad with the suggested alternative I gave: I forgot to mention that the Rules needed to be "Otherwise" nested to make it work properly; sorry about that! I also should have written: "self.Position.Y" instead of "scene.ActorMoving.Position.Y". Apart from those things, it was alright... ;-)

    Anyhow, I've done a little test for you; I'm hoping I've got what you're after. At least the way I've done it, it's easier to see what's going on if you want to adjust any of the Y coordinates:

    https://dl.dropbox.com/u/14060718/UP DOWN TEST DG.gameproj.zip

    A refinement, if you wanted, would be to replace all Change Attributes with Interpolate, setting the time to 0.1 seconds perhaps.

  • ToecutterToecutter Member Posts: 19
    Thank you thats exactly how I want it to work. Weird thing is when using the same instructions on a new project it always gets stuck on the 2nd point and then stops even when the instructions are exactly the same! I've had quite afew crashes at the moment so might need to reinstall :(
    If I wanted it to travel between just three points (Lets say 60, 160 & 260 on the Y axis) would I just change the amounts on the down key rule to:

    Attribute self.position.Y = To. 260

    Change Attribute
    Change Attribute self.position.Y To.160

    Thanks for all the help
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thank you thats exactly how I want it to work. Weird thing is when using the same instructions on a new project it always gets stuck on the 2nd point and then stops even when the instructions are exactly the same! I've had quite afew crashes at the moment so might need to reinstall :(
    My guess is that you've put some of the otherwise stuff in the wrong Otherwise sections; use the last made Change Attribute's otherwise section as you go, if you see what I mean.... that will sort it for you without making any crashes.

    If you just wanted the 3 points, then yes, just take away all reference to the 4th point. If you have any trouble, I'll amend the test file accordingly, if you like.

  • ToecutterToecutter Member Posts: 19
    Yep missed the otherwise stuff.

    Seem to be having real trouble with this. Tried adding up & down buttons instead of the up and down keys but it will only move between 2 points! :((

    If you can amend the file to 3 points I would be very greatfully.
  • ToecutterToecutter Member Posts: 19
    Thank you!
    Added separate controls today (instead of arrow keys) and remembered to use the "otherwise" bit this time :D
    Thank you for all the help!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    You're welcome. :-)
Sign In or Register to comment.