# Help needed in Wall Detection

• DooMZ81
• Newbie
• Joined: Oct 13, 2003
• Posts: 9
• Loc: SIngapore
• Status: Offline

January 11th, 2004, 8:11 pm

I create a simple ball control with keypress direction, if i add some wall around the ball,is there any simple script to detect the collision?if yes any simple script to block the ball from passing through the wall?

Below are the script of the ball

Step2: Turn it into a movieclip.

Step3: Right click on it> Actions.

Step4: Copy and paste following code.

speed = 5;
}
(This determines the allround speed)

Step5: Change the digit 5 to the speed you want.

Step6: Click on the } sign.

Step7: Copy and paste following code.

onClipEvent (enterFrame) {
if (key.isdown(key.LEFT)) {
_x-= speed;
}
if (key.isdown(key.RIGHT)) {
_x+= speed;
}
if (key.isdown(key.DOWN)) {
_y+= speed;
}
if (key.isdown(key.UP)) {
_y-= speed;
}
}

(This determines the position of itself relative to the speed varible)

Step8: Control> Test Movie
• Anonymous
• Bot
• Joined: 25 Feb 2008
• Posts: ?
• Loc: Ozzuland
• Status: Online

January 11th, 2004, 8:11 pm

• DooMZ81
• Newbie
• Joined: Oct 13, 2003
• Posts: 9
• Loc: SIngapore
• Status: Offline

January 13th, 2004, 1:13 am

My eariler post no 1 seems to help me.If i draw a line and symbol the line as Line1 and set it to graphic,then i create a ball using the script below

onClipEvent (enterFrame) {
if (key.isdown(key.LEFT)) {
// left_boundaray can be manually set or you can set it to a property of a movie clip
// This time instead of comparing _x with left_boundary, we are checking
// _x-_width/2....this is basically the left side of your object.
if (_x-_width/2>left_boundary) {
_x -= speed;
}
}
}

or

onClipEvent (enterFrame) {
if (key.isdown(key.LEFT)) {
// left_boundaray can be manually set or you can set it to a property of a movie clip
if (_x>left_boundary) {
_x -= speed;
}
}
}

what should i add in to stop my ball frm passing through the Line1

• UNFLUX
• Genius
• Joined: Dec 20, 2002
• Posts: 6382
• Status: Offline

January 13th, 2004, 10:12 pm

no reason for you to post 2 questions saying no one wants to
help. Simply be patient, as it's quite possible that no one has
UNFLUX.FOTO
• lostinbeta
• Guru
• Joined: Jun 26, 2003
• Posts: 1402
• Status: Offline

January 14th, 2004, 10:16 am

Yeah, situations like this involve a more in depth solution and OZZU doesn't exactly have the biggest selection of ActionScripters.

Anywho, this file is from a while ago and can probably use some updating, but I currently don't have time for all that jazz.

Things you should get to know previously:

1) What is hitTest() and how is it used?

2) What is getBounds() and how is it used?

These answer can be found in the Actionscript Reference that comes with Flash and/or at http://www.macromedia.com or even just a google search for information on them.

I could post an explanation on them, but frankly getBounds() is quite a confusing thing at first and I really don't know where to begin with explaining what it does and how it works.

Anywho, here is the file, happy learning....

http://www.lostinbeta.com/ozzu/wallHit.fla

## Post Information

• Total Posts in this topic: 4 posts
• Users browsing this forum: No registered users and 49 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.