Making an actor constrained to 4 positions

sor3ns3nsor3ns3n Member, PRO Posts: 28

Hi, maybe i am typing in the wrong thing in order to find the relevant information to create this behaviour
But what i want is:

1 Actor that has 4 specific positions and can only move to those positions by moving left or right

Thank you in advance :)

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2016

    We need more details...

    Are the X positions equidistant? That is, something like self.PositionX=100, 150, 200, and 250?

    Does the actor "snap" into position (e.g. x=150... press left arrow... now x=100)? Or does it interpolate smoothly to the new position?

    I know what you mean by "constrain" but in terms of GameSalad rules, you probably don't actually want to constrain anything. Once we find out more info from you, we can suggest some solutions.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • sor3ns3nsor3ns3n Member, PRO Posts: 28
    edited December 2016

    Ye so the positions are like you said
    pos 1 x = * y = 200
    pos 2 x = * y = 200
    pos 3 x = * y = 200
    pos 4 x = * y = 200

    and i want it to move smoothly, left and right, using the touch function.
    I just cant seem to find out how. all i can manage is to move left and right (basic movement)

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2016

    What does "pos 1 x = * y = 200" mean?

    What are the actual, numerical, X positions (see my example)?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • sor3ns3nsor3ns3n Member, PRO Posts: 28
    edited December 2016

    Ok so I want this actor to move between these exact positions and also be bound to these positions

    position 1: x = 80, y = 150
    position 2: x = 150, y = 150
    position 3: x = 230, y = 150
    position 3: x = 300, y = 150

    and it can only move left or right.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Is there a reason that position 3 (the first "position 3") is at 230 instead of 220? I know I'm asking a lot of follow-up questions but it would be much easier to program this is x=220 there. Then it's just a matter of interpolating 70 pixels left or right:

    If [touch for left]
         Change Attribute self.newX to self.Position.X-70
         Timer after 0 seconds [run to completion checked]
              Interpolate self.Position.X to self.newX

    If [touch for right]
         Change Attribute self.newX to self.Position.X+70
         Timer after 0 seconds [run to completion checked]
              Interpolate self.Position.X to self.newX

    Obviously, you'd have to prevent the user from touching/swiping left from position 1 or right from position 4. You can do that by wrapping the "touch for left" rule above in an If attribute self.Position.X ≥ 150 condition and wrapping the "touch for right" rule above in an If attribute self.Position.X ≤ 230 condition.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • sor3ns3nsor3ns3n Member, PRO Posts: 28

    Ok thanks heaps! Iv got the movements working, but i just don't seem to understand this part exactly:

    "Obviously, you'd have to prevent the user from touching/swiping left from position 1 or right from position 4. You can do that by wrapping the "touch for left" rule above in an If attribute self.Position.X ≥ 150 condition and wrapping the "touch for right" rule above in an If attribute self.Position.X ≤ 230 condition."

    Iv also tried using collision and colliding with walls and it doesnt seem to work :sweat:

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited December 2016

    If you're interpolating the actor's position, you wouldn't use collision rules partly because it's not necessary and partly because collision rules don't work with interpolation.

    What don't you understand? "Wrapping a rule" just means putting one rule inside another like this:

    If attribute self.Position.X ≥ 150
         If [touch for left]
              Change Attribute self.newX to self.Position.X-70
              Timer after 0 seconds [run to completion checked]
                    Interpolate self.Position.X to self.newX

    The idea is that when the actor is at x=150 or above, you want to enable moving left whereas when x<150 you want to disable it because the actor is/will be at x=80.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.