Changing the actors direction when colliding with the wall
Lucamc
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
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)
POLAR ROLLOUT (New Line-Drawing Physics Puzzler!) - FREE Download
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).
@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
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 !
@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
Does this help?
@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' ?
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?
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
Did you try my suggestion above ?