Welcome to Dream.In.Code
Become an Expert!

Join 150,418 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,101 people online right now. Registration is fast and FREE... Join Now!




Flash hitTest Problem

 
Reply to this topicStart new topic

Flash hitTest Problem

alohachow
30 Mar, 2008 - 05:27 PM
Post #1

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 5

I am currently making a flash game but I'm confused with hitTest. It can sometimes detect collision sometimes not. Especially when my game speed becomes fast.

Here's my code:

c = undefined;

if(c == undefined)
{
if(this.mcCrocline.hitTest(_root.mcTreeline))
{
hitCount(); //function
c = true;
}

}

Please help me.
User is offlineProfile CardPM
+Quote Post

Tom9729
RE: Flash HitTest Problem
30 Mar, 2008 - 06:01 PM
Post #2

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,594



Thanked: 12 times
Dream Kudos: 325
My Contributions
I've never programmed with flash, but do you know how it's testing for collisions by any chance? Is it a method you wrote, or part of some library?

I was working on collision detection in a 2d game a few months back. The way I put together involved using circles around the center of my sprites, and then testing for intersections (in a nutshell).

At high speeds, my collision circles would "jump" right over each other. If the circles were of different sizes (one really small, or one really big one) sometimes they would even jump inside each other).

All of this would cause somewhat flaky collision detection. sad.gif

A thread on it here.
User is online!Profile CardPM
+Quote Post

Dribbles88
RE: Flash HitTest Problem
2 Apr, 2008 - 08:53 PM
Post #3

New D.I.C Head
*

Joined: 9 Mar, 2008
Posts: 16


My Contributions
a method that i use frequently is put something in each function that will show you that it is working(visibly). like have a number on stage, name the instance Collision. once the collision detects it, have it increment and see if that would help you understand how your collision detection works, then you can modify it to your needs. let me know what you tried and i'll look into it a little more.
User is offlineProfile CardPM
+Quote Post

mullwaden
RE: Flash HitTest Problem
14 Apr, 2008 - 12:19 PM
Post #4

New D.I.C Head
*

Joined: 18 Nov, 2005
Posts: 2


My Contributions
WE you've stumbled upon a tricky subject. Hittest is not very good since it only checks once every frame which sometimes may not be enough.

The easiest thing to do is increase the framerate, flash probably runs at 12-30 fps, you can increase that a bit.

The second easiest thing to do is to save the objects like a position and a radius, so you represent them with spheres (circles in 2D). Its easy to check if they collide (sphere collision detection, google it ! ). For the high-speed cases you have to use variable timestep. That is, when you check if your spheres collide, if you find they don't you try to figure out when they will collide (so now you need a speed for each sphere aswell). If there will be a collision within the length of the frame do something (easiest is just to call it a collision).
User is offlineProfile CardPM
+Quote Post

alohachow
RE: Flash HitTest Problem
14 Apr, 2008 - 05:09 PM
Post #5

New D.I.C Head
*

Joined: 30 Mar, 2008
Posts: 5

It's part of the Flash Library. I'm using the hitTest code. You can find it under flash help to learn more about it.


QUOTE(Tom9729 @ 30 Mar, 2008 - 07:01 PM) *

I've never programmed with flash, but do you know how it's testing for collisions by any chance? Is it a method you wrote, or part of some library?

I was working on collision detection in a 2d game a few months back. The way I put together involved using circles around the center of my sprites, and then testing for intersections (in a nutshell).

At high speeds, my collision circles would "jump" right over each other. If the circles were of different sizes (one really small, or one really big one) sometimes they would even jump inside each other).

All of this would cause somewhat flaky collision detection. sad.gif

A thread on it here.



Thanks a lot. I'll try that idea.

QUOTE(mullwaden @ 14 Apr, 2008 - 01:19 PM) *

WE you've stumbled upon a tricky subject. Hittest is not very good since it only checks once every frame which sometimes may not be enough.

The easiest thing to do is increase the framerate, flash probably runs at 12-30 fps, you can increase that a bit.

The second easiest thing to do is to save the objects like a position and a radius, so you represent them with spheres (circles in 2D). Its easy to check if they collide (sphere collision detection, google it ! ). For the high-speed cases you have to use variable timestep. That is, when you check if your spheres collide, if you find they don't you try to figure out when they will collide (so now you need a speed for each sphere aswell). If there will be a collision within the length of the frame do something (easiest is just to call it a collision).



Thanks for the ideas.

QUOTE(Dribbles88 @ 2 Apr, 2008 - 09:53 PM) *

a method that i use frequently is put something in each function that will show you that it is working(visibly). like have a number on stage, name the instance Collision. once the collision detects it, have it increment and see if that would help you understand how your collision detection works, then you can modify it to your needs. let me know what you tried and i'll look into it a little more.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:21PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month