Caught in a Loop! Help!

rhinokeyrhinokey Member Posts: 158
edited May 2012 in Working with GS (Mac)
i'm starting on a little puzzle game and i'm running into an issue.

I want my character to walk one dir until he bumps into a wall then turn the other way and walk until he hits a wall.
I've tried this several ways, most common is to add an attribute to the character, I've used both Boolean, and text to achieve this, with Boolean I've had a right and left attribute, that i could turn on and off, and with text i made a direction attribute, that i either put left or right in.

i then set up rules that say if left is true (or left entered in text) to change attribute motion linear x -30, and vice verse for right

this all worked fine,

but the next step to make him turn when he hits a wall. i put in walls and put them under a character collision tag.
and made a rule that says
if character collides with that wall
and left is true
change left to false, and right to true

i then made another rule opposite this. but most the time he gets stuck on the wall and is just vibrating, i assume he's getting caught in a loop, where it changes his direction, but since he is still touching the wall, it instantly switches it back

can someone please give me an info on stopping these kind of loops, i'm sure its something that will come up often

Best Answer

  • MotherHooseMotherHoose Posts: 2,456
    edited May 2012 Accepted Answer
    @rhinokey … wow! for someone new to GS … you are doing super!

    walls are great … when you want the multiple Collide actions/changes

    with your actor … colliding with walls … is not working good
    and adding new attributes are still not getting things smooth

    in a GS project during runtime the computer is always tracking the X,Y of your actors
    … it always knows where everything is in relationship to everything in the scene
    so using that knowledge … simply add rules for when something is valid: do this

    when your MLV is constant and your Graphics animation is constant …

    this demo uses Graphics > Flip Horizontally for animation direction
    and the X position of actor to control left/right Motion: Linear Velocity X
    with no walls nor collide behaviors … (save the collides/overlaps for onScreen elements)

    demo download

    @};- MH

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited May 2012
    Edit: what tshirtbooth said

    It should work to just have When actor overlaps or collides with actor of type wall --> change attribute self.motion.linear velocity.x to self.motion.linear velocity.x*-1

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @tshirtbooth lol nope, it's no different. A lot of times when I refresh my browser, it doesn't show the latest replies. I did check! Sorry about that...

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

  • rhinokeyrhinokey Member Posts: 158
    thanks everyone, here is what i have had acomplished before i posted, in this version
    i have the turn at walls working. but its a pretty complex systems i used, and i know theres
    got to be a simpler way. I have not yet tried the advice posted above, I will as soon as i get home from work tonight. you can see in my version sometimes when it touches the wall the anim stutters back and forth between left and right instead of just smoothly swapping. (the bear anim is a place holder i grabbed offline)

    well i am running off to work now, hope to work this out tonight
  • rhinokeyrhinokey Member Posts: 158
  • MotherHooseMotherHoose Member Posts: 2,456
    for simpler … did you download my demo?
    though see with link … you do need walls in scene … and vertical flip
    for them
    Rule: when
    Event: overlaps or collides with wall
    -changeAttribute: graphics flip horizontally
    -changeAttribute: MLV
    -changeAttribute: graphics flip vertically

    oh … @rhinokey … just had such fun with the arcade play of your project!
    I did succeed … though painstakingly laughing all the way to the door!

    great fun! … will like to see and enjoy your progress with this one!

    image MH
  • rhinokeyrhinokey Member Posts: 158
    thanks, cant wait till i get home and can work on this more.
    I'm not a total noob, i've been in the game industry about 9-10 years but mostly doing art on mmo games. thi is my first attempt at creating my own in game salad

    after getting the motion and gravity swaps smoother i'm going to work on pushable blocks, pressure plates that trigger doors or other objects, roaming monsters to avoid. and then figure out how to make the game area bigger, where the screen follows the bear around the level as you move. and then the hard part, creating a series of fun prototype puzzle levels.. and then the fun part, making a ton of art sprites (co worker of mine is sposed to be helping out with art.
  • rhinokeyrhinokey Member Posts: 158
    edited May 2012
    holly smokes that did it Tshirt! i at first didnt get what you meant, i didnt know you could put the atribute string in the secong box of the atribute change , that works perfectly now! many thanks!

    and motherhooose, thants for that alternate technique, i cant use it on my main char, but i may use that method for my monsters that need to turn around before walking off ledges!



    oh just a silly question to help me understand the math in this
    my lin vel was stet at +30 to begin,

    using this method "self.motions.lin.vel.x to -self.motions.lin.vel.x"
    wouldnt that be +30 Minus +30 = 0? so it seems on bounce the character should stop which would be undesirable, but he does not, he stays at +30
    also on the other direction which is -30 useing that rule seems like it would be -30 minus -30 = 0

    so again i'm happy this is workin out properly, but just curious why its not.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @rhinokey the change attribute behavior for switching directions is not a subtraction but a multiplication by negative one. It's velocity*(-1), which can also be written as velocity*-1 or as
    -velocity.

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

Sign In or Register to comment.