Forum Topic: Circle hitTest problem

(223 views • 15 replies)

This topic is 1 page long.

<< < > >>
Resigned

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 07:41 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

As u are all well aware. Simple hitTests just create this collision square. I have been spending quite a while trying to make the hittest radial but even As:Main didn't really help. So I have decided to give specifics. My circle mc is _root.main and it is 50 by 50. I was wondering if someone could give me a simple code to make the circle have a circular hitTest.

Also maybe tell me where to put all my hitTest code (If it has to be specific)

: Nothing

BBS Signature

None

Cecemel

Reply To Post Reply & Quote

Posted at: 6/9/08 07:45 AM

Cecemel DARK LEVEL 16

Sign-Up: 08/19/05

Posts: 1,078

The easiest way is just using a for loop, and shapeflag.

<3


None

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 07:52 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

I have looked at the tuts but they don't work. And when i write one myself it still acts with the stupid square hitTest

:(

: Nothing

BBS Signature

None

Hate-or-Hate

Reply To Post Reply & Quote

Posted at: 6/9/08 07:56 AM

Hate-or-Hate NEUTRAL LEVEL 04

Sign-Up: 05/12/08

Posts: 127

i dont know what shapeflag is but i think the best way is the hittest with the spots
hitTest(0,0,true) will make it work in the middle you may do few points ... well search for a tuts for this there are alot here...

Hi!


None

Cecemel

Reply To Post Reply & Quote

Posted at: 6/9/08 08:04 AM

Cecemel DARK LEVEL 16

Sign-Up: 08/19/05

Posts: 1,078

for (i=1; i<=360; i += 10) {
X = (Math.cos(i*(Math.PI/180))*_width/2)+_x;
Y = (Math.sin(i*(Math.PI/180))*_width/2)+_y;
if (whatever.hitTest(X, Y, true)) {
stuff
}

put this in the circle movieclip if its center is in its center :]
it basically gets 360/10=36 points on the circle and tests if whatever hits any of them.

<3


None

CaiWengi

Reply To Post Reply & Quote

Posted at: 6/9/08 08:04 AM

CaiWengi EVIL LEVEL 07

Sign-Up: 09/17/04

Posts: 1,517

onClipEvent (load) {
radius = ###
}
onClipEvent (enterFrame) {
for (i=0; i<360; i++) {
X = (Math.cos(i*(Math.PI/180))*radius)+_x;
Y = (Math.sin(i*(Math.PI/180))*radius)+_y;
if (_root.shape.hitTest(X, Y, true)) {
trace("hit")
}
}
}

Taken from here, written by 23450

AS 2

Sig by ApothicFlash <3

BBS Signature

None

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 08:09 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

I have triied both your codes. Could someone maybe post a small fla of a circle with the code on it cause I put it on mine.
onClipEvent (enterFrame) {
for (i=1; i<=360; i += 10) {
X = (Math.cos(i*(Math.PI/180))*_width/2)+_x;
Y = (Math.sin(i*(Math.PI/180))*_width/2)+_y;
if (_root.main.hitTest(X, Y, true)) {
trace("yay");
}
}
}

It is tracing yay always. what is it hitTesting. what does the X,Y, true mean. These are sort of the questions i need answered....

: Nothing

BBS Signature

None

Cecemel

Reply To Post Reply & Quote

Posted at: 6/9/08 08:09 AM

Cecemel DARK LEVEL 16

Sign-Up: 08/19/05

Posts: 1,078

At 6/9/08 08:04 AM, CaiWengi wrote: for (i=0; i<360; i++) {

this would lag like hell though, 1 point every 10 pixels is more than enough.

<3


None

Swordsbite

Reply To Post Reply & Quote

Posted at: 6/9/08 08:32 AM

Swordsbite NEUTRAL LEVEL 08

Sign-Up: 03/10/08

Posts: 636

In the stuff I make, I have a variable on the circle called

radius

Now, you would set that up so it works like this

onClipEvent(load) {
radius = 8.5;
}

You can change the 8.5 to something smaller or higher depending on how it turns out in your test.

Now, for the hitTests, you would use a while loop. So you make have something like this

	_x += Key.isDown(Key.RIGHT)*power;
	_x -= Key.isDown(Key.LEFT)*power;
	_y += Key.isDown(Key.DOWN)*power;
	_y -= Key.isDown(Key.UP)*power;
	// wall22 HitTests 
	while (_root.wall2.hitTest(_x, _y+radius, true)) {
		_y--;
	}
	while (_root.wall2.hitTest(_x, _y-radius, true)) {
		_y++;
	}
	while (_root.wall2.hitTest(_x-radius, _y, true)) {
		_x++;
	}
	while (_root.wall2.hitTest(_x+radius, _y, true)) {
		_x--;
	}

And there ya go. Dont worry about the power, I always write that as my speed variables and I just added it in so u could see.

Good Luck on your game

Footsteps of zrb || As:Main || As3:Main || Flash Tutorials || PM me for help. ||


None

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 08:41 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

what is the _root.wall2 u are referring to. Does that mean it hits a wall called wall2?
I am testing out your code though.

I AM ALMOST IN DESPAIR....
I just need a freaking radial hitTest and it is becoming so bloody hard.

I can code all this shit in my game but I can't do a simple hitTest....

Moans*

I still recon someone should upload a small fla that works...

WHAT AM I DOING WRONG!
And i gtg sleep now which sucks.

: Nothing

BBS Signature

None

CaiWengi

Reply To Post Reply & Quote

Posted at: 6/9/08 08:43 AM

CaiWengi EVIL LEVEL 07

Sign-Up: 09/17/04

Posts: 1,517

At 6/9/08 08:04 AM, CaiWengi wrote: onClipEvent (load) {
radius = ###
}

onClipEvent (enterFrame) {
for (i=0; i<360; i++) {
X = (Math.cos(i*(Math.PI/180))*radius)+_x;
Y = (Math.sin(i*(Math.PI/180))*radius)+_y;
if (_root.shape.hitTest(X, Y, true)) {
trace("hit")
}
}
}

Taken from here, written by 23450

AS 2

If you dont understand it then click the link. What more do you want?

Sig by ApothicFlash <3

BBS Signature

None

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 08:45 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

But I don't understand. What is the X,Y. And when i have an if (hitTest) bla bla.... statement then I don't know where to put it. It traces hit forever as well so I need help.

: Nothing

BBS Signature

None

Morningdeath

Reply To Post Reply & Quote

Posted at: 6/9/08 08:50 AM

Morningdeath FAB LEVEL 10

Sign-Up: 01/16/07

Posts: 263

FUCK. I got it. Soz for wasting your time. And thanks for helping. I played with your codes and it finnally worked. TY now this topic can die...

: Nothing

BBS Signature

None

Vengeance

Reply To Post Reply & Quote

Posted at: 6/9/08 08:52 AM

Vengeance EVIL LEVEL 28

Sign-Up: 03/18/05

Posts: 5,033

At 6/9/08 08:09 AM, Morningdeath wrote: Blah blah blah
onClipEvent (enterFrame) {
for (i=1; i<=360; i += 10) {
X = (Math.cos(i*(Math.PI/180))*_width/2)+_x;
Y = (Math.sin(i*(Math.PI/180))*_width/2)+_y;
if (_root.main.hitTest(X, Y, true)) {
trace("yay");
}
}
}

The problem here is that you're checking if the object is hitting itself.

onClipEvent (enterFrame) {
for (i=1; i<=360; i += 10) {
X = (Math.cos(i*(Math.PI/180))*_width/2)+_x;
Y = (Math.sin(i*(Math.PI/180))*_width/2)+_y;
if (_root.THEOBJECTHATYOUWANTITTOHIT.hitTest(X, Y, true)) {
trace("yay");
}
}
}

========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

None

WolfAkela

Reply To Post Reply & Quote

Posted at: 6/9/08 08:53 AM

WolfAkela LIGHT LEVEL 08

Sign-Up: 12/19/05

Posts: 2,327

If you're just trying to see if a point is inside the circle you should just use the distance formula. Distance = radius


None

Swordsbite

Reply To Post Reply & Quote

Posted at: 6/9/08 09:04 AM

Swordsbite NEUTRAL LEVEL 08

Sign-Up: 03/10/08

Posts: 636

Heres a fla without all this complicated hitTests (suposively i dont understand for loops yet) that will help you

yes, wall2 is just the levels instance name, youll see

http://spamtheweb.com/ul/upload/090608/3 2676_Circle_HitTest.fla

Footsteps of zrb || As:Main || As3:Main || Flash Tutorials || PM me for help. ||


All times are Eastern Standard Time (GMT -5) | Current Time: 09:17 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!