Changing the actors direction when colliding with the wall

LucamcLucamc Member, PRO Posts: 60

Hi,
I would like my actor when moving towards right and then colliding with the wall to move than towards the left and then when colliding with the left wall to move back towards the right and so on...
At the moment my actor sticks on the wall and won't change direction.
I would appreciate any help.

Comments

  • supafly129supafly129 Member Posts: 454
    edited January 2015

    You can use the "Change Velocity" or "Change Attribute" behaviors, for instance:

    When actor overlaps with left wall:
    Change Velocity (direction 0), Relative to (Scene), Speed (whatever you want)

    When actor overlaps with right wall:
    Change Velocity (direction 180), Relative to (Scene), Speed (whatever you want)

    OR

    When actor overlaps with left wall:
    Change Attribute--> Motion --> Linear X to (positive number)

    When actor overlaps with right wall:
    Change Attribute--> Motion --> Linear X to (negative number)

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    You can simply use the built in physics to have objects bounce off each other.

    Make sure the wall cannot be moved (uncheck 'moveable') and give the actor a collision behaviour (with the wall).

  • LucamcLucamc Member, PRO Posts: 60

    @Socks It only bounces a little but does not change direction and from @supafly129 it didn't work either.

    I made a screenshot so maybe helps you

  • SocksSocks London, UK.Member Posts: 12,822

    @Lucamc said:
    I made a screenshot so maybe helps you

    You've got two collides for 'Ground' ?

    If you can post a screenshot of your rules without the important bits hidden that would be more useful !

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

    @Socks Some people prefer to hide their bits in photos.

    @Lucamc If you mouse over the attribute name or click on the ellipsis (...), you should see the full attribute name. For expressions, clicking on the 'e' will do the same.

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @tatiang said:
    Socks Some people prefer to hide their bits in photos.

    :smile:

  • LucamcLucamc Member, PRO Posts: 60


    Does this help?

  • SocksSocks London, UK.Member Posts: 12,822

    @Lucamc said:
    Does this help?

  • LucamcLucamc Member, PRO Posts: 60

    @Socks
    self.Motion.Linear Velocity X

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @Lucamc said:
    Socks
    self.Motion.Linear Velocity X

    Try getting rid of that constrain behaviour and using either a change attribute (self.Motion.Linear Velocity X) behaviour or a change velocity behaviour.

    Also, why two collide behaviours for the 'ground' ?

  • LucamcLucamc Member, PRO Posts: 60

    I have the constrain attribute off but it doesn't move now.
    How should the Rule look like so when it hits the right wall it will move left and when it hits the left wall it will move right?

  • MentalDonkeyGamesMentalDonkeyGames Member Posts: 1,276

    If you have the "motion.Linear Velocity X" in a "Constrain Attribute", the actor will constantly try to move in the chosen direction (in your case right). So even after it collides and bounces, it will still move left.

    It´s basically telling the actor to always move right.

    Put it in a "Change Attribute" instead.

    Mental Donkey Games
    Website - Facebook - Twitter

  • SocksSocks London, UK.Member Posts: 12,822

    @Lucamc said:
    I have the constrain attribute off but it doesn't move now.

    Did you try my suggestion above ?

Sign In or Register to comment.