Set diferent movement positions

tomi2711tomi2711 Member Posts: 1
edited November -1 in Working with GS (Mac)
I am trying various ways and i was not able to find a solution to my problem. I want to make my character to move into 4 predefined positons. These positions would be placed in the X axis. Is there any way to make this? if my explanation is not to clear i'll try to make it better with an example:

The positions would be set in this order: 1 2 3 4. for example if my character is located in position 2 to move to 1 or 3 you will need to press the left and right key respectively. The position number 1 will be the first one, and as with 4, if i press the left button while being in position 1 i want nothing to happen.

The best way I was able to find was:

- make a rule that said: actor recieves event -> key -> left, change attribute self.PositionX to self.PositionX -60.
- make a rule that said: actor recieves event -> key -> right, change attribute self.PositionX to self.PositionX +60.

This was what i wanted but i am having the trouble that my actor bumps into the walls that are next to positions 1 and 4, therefore loose the predifined positions i get to generate with what i have just said.

I already tried also:

- make a rule that said: actor recieves event -> key -> left, move toward 180º
- make a rule that said: actor recieves event -> key -> right, move toward 0º

But the problem here is that my actor moves smoothly and i don't want this to happen: i need my actor to move abruptly, and as i said into this 4 predefined places.

Thank you very much, i appreciate your help.

Tomi.

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Hi Tomi,
    you're on the right track. Since you have them evenly spaced apart, you could do this for changing the position on the X axis.

    1. Create an integer called 'spacenum'

    2. Create Rule 1:
    Condition 1: On key pressed "left":
    -> Change Attribute 'spacenum' = min(1,'spacenum'-1)

    3. Create Rule 2:
    Condition 1: On key pressed "right":
    -> Change Attribute 'spacenum' = max(4,'spacenum'+1)

    4. Constrain self.Position.X to 60*'spacenum'+(some offset)
Sign In or Register to comment.