Help needed in Wall Detection

  • DooMZ81
  • Newbie
  • Newbie
  • DooMZ81
  • Posts: 9
  • Loc: SIngapore

Post 3+ Months Ago

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

Step1: Make your object.

Step2: Turn it into a movieclip.

Step3: Right click on it> Actions.

Step4: Copy and paste following code.

onClipEvent (load) {
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
  • DooMZ81
  • Newbie
  • Newbie
  • DooMZ81
  • Posts: 9
  • Loc: SIngapore

Post 3+ Months Ago

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


Help please...
  • UNFLUX
  • Genius
  • Genius
  • User avatar
  • Posts: 6376
  • Loc: twitter.com/unflux

Post 3+ Months Ago

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
an answer for you.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

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 10 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.