View Full Version : [AS2] moving a mc within a boundry

10-13-2009, 12:44 PM
Hi Friends,

I am doing a game, in that I have to move the mc within a boundry limit (i.e. moving over a path). If the mc hits on the wall, it should not move in the direction, which we move.

Note: Not by just setting the x, y limit. By using the hitTest.

Please help me.
Thanks in advance.

orange gold
10-14-2009, 01:25 AM
_root.onEnterFrame = function() {
if (Key.isDown(Key.RIGHT)) {
"mc's instance name here"._x += + "speed here... ex. 5"
if ("your mc's instance name here".hitTest(_root."right_wall's instance name here")) {
"mc's name"._x += - "speed it bounces off of the wall here... ex. 5"

this way if the ball is traveling right at say a speed of 5, and it hits the right wall it will bounce off (to the left) at a speed of say 5, then the ball will hit the wall and not move because its going both directions at a speed of 5 which averages out to a net speed of 0. now it can not pass the wall but still be moved off of it