Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-13-2009, 12:44 PM   #1
anand.as2
scripter
 
Join Date: Sep 2009
Posts: 56
Thumbs up [AS2] moving a mc within a boundry

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.
anand.as2 is offline   Reply With Quote
Old 10-14-2009, 01:25 AM   #2
orange gold
got as?
 
Join Date: May 2007
Posts: 628
Default

ActionScript Code:
_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
__________________
Feel free to PM me if you have a question
orange gold is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.