Moving an actor in increments

okkleokkle Member Posts: 32
edited November -1 in Working with GS (Mac)
Hi everyone,
I'm having a bit of trouble getting an actor to move how I want it too.

Basically I have 2 buttons both moving an actor along the X plane in either direction but I need to limit that movement with each button press. So for example you press button1 and the actor slides right by 40 then stops, press it again it moves right by 40 again, press button 2 and it will slide 40 in the opposite direction and so on.

In my current set up I have created a boolean attribute for the left and right movements called 'actor move L' and 'actor move R' which are false by default.

In the actor clip I have the rule:

`
if 'actor move R' = true
> Move Too X: self.Position.X +40, Y: 0, Speed 300, relative to actor.
`
The in the button I have the rule:

`
When actor receives event: touch is pressed
> Change Attribute 'actor move R' to true

Otherwise Change Attribute 'actor move R' to false
`
However this just means that for the duration of that button press the block keeps moving, and if "run to completion" is ticked it never stops. So basically, how do I get it to move by that distance of 40 and then stop until the button is pressed again?

I was able to make it snap abruptly by the distance by setting an integer attribute, constraining the actor's X position to that and the having the button increase the integer by 40, however I want to get a smooth movements between the two points.

Any help is greatly appreciated! Thanks,
- Olly

Comments

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    You could try using interpolate self.position.x to self.position.x +40 and the duration you want it to do it in.

    On the button you could have your rules trigger when touch is released and have it reset the left or right booleans after say 0.1 seconds.
  • okkleokkle Member Posts: 32
    My good sir you are a genius! I cannot thank you enough! I didn't know that was what interpolate does, and I can even ease the movement in and out this way :D

    The distance is a little odd for some reason, it moves way further than 40 pixels, I guess I can adjust this manually though.

    Thank you so much!
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    okkle said:
    My good sir you are a genius! I cannot thank you enough! I didn't know that was what interpolate does, and I can even ease the movement in and out this way :D

    The distance is a little odd for some reason, it moves way further than 40 pixels, I guess I can adjust this manually though.

    Thank you so much!

    the reason its moving more then 40 pixels is because interpolateing is changing its value constantly over the set time, so +40 keeps growing and becoming a bigger number over the course of the behavior. So what you do is make an attribute and whenever you want to move change that attribute to self.position whatever+40. Then interpolate to that attribute instead of +40 in the interpolate behavior.

    hope that makes sense.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    okkle said:
    My good sir you are a genius! I cannot thank you enough! I didn't know that was what interpolate does, and I can even ease the movement in and out this way :D

    The distance is a little odd for some reason, it moves way further than 40 pixels, I guess I can adjust this manually though.

    Thank you so much!

    Interpolate is a mans best friend. Smooth movement and moving stuff into position is awesome with interpolate. You can also use it on self.alpha to fade stuff in or out etc.
    JohnPapiomitis said:
    the reason its moving more then 40 pixels is because interpolateing is changing its value constantly over the set time, so +40 keeps growing and becoming a bigger number over the course of the behavior. So what you do is make an attribute and whenever you want to move change that attribute to self.position whatever+40. Then interpolate to that attribute instead of +40 in the interpolate behavior.

    hope that makes sense.

    Yes as John says, use the button press to change the attribute and then upon that, interpolate to that attribute, that'll make it more reliable.
  • okkleokkle Member Posts: 32
    That does indeed make sense and it's working much more smoothly, thank you both!

    The only question I'm left with now is the buttons are actually moving multiple actors (all instances of the same actor) in the same manner at the same time, do I need to set up an attribute for each actor, or is there a more efficient way of doing this?

    Thanks again!
  • okkleokkle Member Posts: 32
    Just thought I'd reply to this for anyone reading and wanting to do this too.

    In the end I set up a new attribute for each actor and then edited each actor in the stage rather than in the library at the side. I don't know if this is the most efficient way to do this, but it has kept the library nice and clean and it all works :)
  • okkleokkle Member Posts: 32
    Ok guys this is an odd one, I've racked my brains to try and figure it out but I'm truly stumped so I'm hoping you can help me out this one last time.

    Using the method you guys gave me I've got the buttons working and moving the actor exactly how I wanted. The button only affects the X axis, so if I duplicate the symbol and reposition it in the Y axis it should mimic the movement along the X axis exactly when the button is released. However the new duplicate moves slightly faster. It still ends in the correct position, moves over the correct period of time, it just starts and finishes slightly ahead of the original. Not much, but enough to notice and break the game.

    I thought it might be something to do with the easing so I tried setting that to linear but that has had no affect. I've tried duplicating it by holding Alt and by adding it from the main library but it still does it. Even though it's exactly the same in every way bar the Y position.

    Is this something you guys have encountered before? Is it a general bug in Gamesalad?

    Thanks again for all your help so far!
    -Olly
Sign In or Register to comment.