views:

275

answers:

2

Hi, for the past two weeks I've been working on coming up with a collision detection system for my game in flash CS4. No matter what I try for some reason I just can't seem to do it, and I don't know how to fix it. This has never been an issue for me, I would even settle for basic rectangle to rectangle collision if I could, but no matter what I do I end up screwing it at all up. Somehow the collision detection either doesn't work at all, works for one side and jumps the guy through the wall on any other side or I think at one point it worked for two sides as long as I didn't hold down more than one movement key.

I've constantly scrapped what I've done over and over, right now I have no source code to present. I'm totally lost and confused, and my deadline for getting this done is today in a few hours. I really wanted to figure this out on my own but honestly I just don't see what I can do, I've got sphere to sphere collision detection working perfectly for my player and other spheres, but the walls are squares lined up to form long rectangles, and I just can't seem to get it to work. I'm dynamically loading the square-wall blocks as tiles to form a dynamically loaded map, and then I'm iterating through each individual block to determine if collision has occurred with the player. I think somehow I'm not managing the results right, or maybe I somehow need to be able to determine which direction the player hit the wall from, but I just don't know how to do it.

I'm really sorry for not being able to give source code, I just literally don't have anything. I've been staring at the screen for the past 3 hours trying to work something out but nothing is coming to me, so please if anyone can help me with an example from a flash-type game or something similar I would be very grateful! (I've done this countless times in C++, C#, and java. I don't get what is going on in flash :-(((( )

+1  A: 

This may help you... http://www.tink.ws/blog/as-30-hittest/

dome
Oh...thanks! I've tried using hitTestObject but it was so inaccurate it was pointless. I'll try that, thank you very much!
Joe.F
A: 

Don't despair, we've all been there at one point :)

Use a 2d physics engine if it's something more complicated.It can get you up ad running pretty fast:

http://box2dflash.sourceforge.net/

Some tutorials on this can be found here: http://www.emanueleferonato.com/category/box2d/

You can check more tools for flash developers here:

http://flashontherocks.com/flash-developer-toolbox/

Oliver
if someone's having trouble working out a relatively simple collision, giving them a full physics engine to battle with isn't really going to help ;)
grapefrukt
You are right but I find that showing someone to the possibilities is also right.From what I understand he needs a solution to develop his game pretty fast as he now has nothing and he is close to the project's deadline.A physics engine would be the quickest solution in my opinion.If he researches a couple of hours on this, I'm sure he'll be on the straight way. Even more, if he'll be able to handle a physics engine it will be good for him as a game developer so I see it as a good investment.
Oliver