PDA

View Full Version : hitTest help


soundgarden
08-06-2003, 11:34 AM
I have a ball that hits a right wall and left wall. It works fine except for the fact that the ball goes half way into the wall before it changes direction. How do i make it so that the edge of the ball mc hits the wall NOT the center.

dzy2566
08-06-2003, 11:53 AM
Your problem has to do with the actual frames that are being generated by flash. Your ball isn't "hitting" your wall until a frame that happens to show the ball halfway through the wall. The ball just touching the edge of the wall might not even exist.

I read about this in Macromedia Flash MX Game Design Demystified (http://www.amazon.com/exec/obidos/ASIN/0201770210/qid=1060180367/sr=2-2/ref=sr_2_2/104-6995802-2144700). It's a decent book, but I recall the author's solution to this being rather long. I don't think he even used hitTest. What remember involved not only calculating where the ball is and what it might be touching, but where the ball will be in the next rendered frame. It was in the predicted frame that he was doing his calcualtions. If he discovered that the ball would be contacting the wall in the next frame, which could be anywhere from the front end, the middle, or the last pixel of the ball touching the wall, he would put the ball where he wanted it to be during contact with the wall in the next frame. Meaning, if you're moving the ball 5 pixels each frame, if it turned out the the ball would first contact the wall with a 3 pixel overlap, he would sort of intercept the +5 increment for the next frame, position the ball at the wall, and resume his +5 increment in the frame following the contact.



I know this is probably pretty confusing, but it'll get you thinking.

St. Nick
08-23-2003, 11:22 AM
Ummmm.... No. There is a WAY easier way to do it than what that whatever his name is did. The wall is thinking that it wants to intercept with the center of the ball, so you have to trick the wall into thinking that one edge of your ball is the center. You do this by moving the ball in the mc editor over to the right or left of the cross-thingy in the middly. Then when the ball bounces off of the wall (which will be perfect if done CORRECTLY - the wall must have the same change as well) you can use some simple actionscript commands to flip the ball around. Or EASIER STILL, now that I think of it, you could create two (or more) teeny tiny mc's and set the alpha to zero, and have THOSE bounce off of the wall, but they will be part of the ball mc, like, right on the edge of the ball, so you will think that the ball is bouncing. None of this complicated, actionscript runs-my-life stuffs. This works for me, so I know it works.

omega10mg
08-24-2003, 06:50 PM
or just make an invicible wall over and a bit outside your real wall that collides with the ball.. so it looks liek it hits the wall. easy! =)

dzy2566
08-24-2003, 10:38 PM
Well there St. Nick, my norrow-mided friend. I'm sure that it works, sometimes. But to say that you have the solution because you got it to work once is incredibly foolish. There are more ways than one to do things, and there are more variables than you seem to care to notice. Change the incrementation of whatever you have moving to 10 or 20 pixels, and then see if your hitTest still works. It probably won't. Because in one frame it will be out of contact with your wall, on the left, and then in the next frame it will be out of contact with your wall, a few pixels to the right. A frame where they are in contact may not exist, which is why I suggested what I did. Like I said, your way works, yes.....sometimes. Um.................yes.

-whatever his name

webguy
08-25-2003, 02:55 PM
<-- has to agree with dzy due to personal experiences... and I think I actually asked the same question before :)

dzy2566
08-25-2003, 03:09 PM
Thanks for the support webugy :) . I've been wondering about your icon, is that Dana Carvey? Looks like something that might have come from Master of Disguise, though I haven't seen it.

webguy
08-25-2003, 03:26 PM
hehe..no it is Jamie Kennedy from the Jamie Kennedy experiment and Malibu's most wanted. I can talk like him well and I do it at work alot..check out "the malibu rapper is back in town" very funny.

http://www.jamiekennedyworld.com/downloads.htm

dzy2566
08-25-2003, 03:56 PM
Wow. I knew the one with the visor was him, but I didn't know the bald guy was him too. I'll check that link out.

webguy
08-25-2003, 04:04 PM
hehe..yeah that is miles from the jamie kennedy experiment.

dzy2566
08-25-2003, 04:49 PM
Yeah it is. Hey, if you like the type of character he plays in malibu, you should check out the toons a The Romp (http://www.theromp.com) Very funny toons about a player trying to get laid. Not exaclty Jamie Kennedy, but I'm sure you can still appreciate it.