AI Actor to change direction when hitting wall

In my game I have AI actors that spawn in and move in one direction only. I'm trying to get it so that when they hit the side of a wall, they will go back in the opposite direction to the one they were moving in. But only when they hit the side of it, not the top or bottom.
However, I'm not sure how to detect whether the actor has hit the 'side' of the wall in order for me to tell it to change direction at that moment.
Is there a way to do this?
However, I'm not sure how to detect whether the actor has hit the 'side' of the wall in order for me to tell it to change direction at that moment.
Is there a way to do this?
Comments
You could create an interger attribute for the actor called "MovementDirection". Then under the actor, create a couple of rules:
---
Change Attribute: "MovementDirection" to Rand(0,360)
---
Actor Move: Angle to "MovementDirection"
---
On Collision with 'Wall': If "MovementDirection > 180 Then
(MovementDirection = MovementDirection-180)
Else
(MovementDirection = MovementDirection+180)
---
I'll explain a little. Let's say an actor is moving towards angle '90' which is directly up in GameSalad. On collision with the wall, it will check to see if the angle is above '180' or not. If it's above, it will minus 180 from the angle; If it's below it would add 180. In this case, the angle is 90, so it would add 180 which gives 270 which is directly down in GameSalad.
Hope this helps a little.
Or use individual walls for above/below/left and right. Then you could check for the particular collision with your hero object. In one thing I've been working on I had to do this as I had lots of paths on screen defined by walls and and want actors to set off from collision in a similar way to what I think you are talking about. By having the actors for the walls overlaying each other with a very slight protruding in their own rule direction (a top actor sticking out a couple of pixels from the bottom of a block of walls for example) I found I could get things to work. There might be problems if the hero actor was travelling at speed as it might overlap two different wall type sections, but the way I've set things up in my case this is not a problem.
hope that helps
kipper