Moving an actor between points without it leaving a set area
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
-
gyroscope I am here.Posts: 6,598
No probs; here is a revised gamefile, moving up and down over 3 points, not 4:
https://dl.dropbox.com/u/14060718/UP DOWN TEST2 DG.gameproj.zip
Hopefully no more
( but plenty of :-) !
Answers
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
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?
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.
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
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.
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.
Added separate controls today (instead of arrow keys) and remembered to use the "otherwise" bit this time
Thank you for all the help!
You're welcome. :-)