Go Back   kirupaForum > Flash > Game/AI Programming

Reply
 
Thread Tools Display Modes
Old 11-30-2009, 05:55 AM   #1
mordormaster
Registered User
To Hittest or Not To Hittest

Hittesting has become pretty much the most important part of my game. So ive ended up putting 62 hittests on one of four secsions per enemy. So understandably, lag central, anybody got a more efficant way of doing this code.

onClipEvent (enterFrame) {
if (_root.floor.ai1.hitTest (this)) {
_root.floor.enemy1._y+=15
}
if (_root.floor.ai2.hitTest (this)) {
_root.floor.enemy1._y+=15
}
if (_root.floor.ai3.hitTest (this)) {
_root.floor.enemy1._y+=15
}
if (_root.floor.ai4.hitTest (this)) {
_root.floor.enemy1._y+=15
}
if (_root.floor.ai5.hitTest (this)) {
_root.floor.enemy1._y+=15
}
}
mordormaster is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-30-2009, 07:30 AM   #2
dandylion13
Registered User
Hello,

Can you explain what you need your collision detection to do?
dandylion13 is offline   Reply With Quote
Old 11-30-2009, 07:31 AM   #3
OmniNL
Registered User
I know Tonypa had some great tutorials with hittests, although i think they are more tile related.
http://www.tonypa.pri.ee/tbw/start.html

He doesn't use hitTest() at all, but uses the corners of the MC to detect others.
Hope that helps a bit
OmniNL is offline   Reply With Quote
Old 11-30-2009, 08:54 AM   #4
mordormaster
Registered User
I have my Map movieclip called Floor, i have my enemy called Goblin_Swordsman_1 and i have my enemy hittesting part. There are four secsions. As the bottom secsion touches an object it moves the goblin up by 15 pixels. This just about works. I have several objects that the goblins shouldn't be able to walk through. I call these Ai1 Ai2 etc. Any ideas? If you need an .Fla il post.
mordormaster is offline   Reply With Quote
Old 11-30-2009, 11:12 AM   #5
TOdorus
Hot 'n Funky
 
TOdorus's Avatar
Location Nijmegen, Netherlands

Posts 390
Introduce a broadphase.

A simple one would be to first do a circle vs circle check with math. Just give your objects a radius which encompasses the whole graphic and first check if those circles are overlapping and only then perform a more expensive hittest.

Another way is to use a grid, but this only saves with A LOT of objects. At the start of every update cycle you wipe the grid, then loop through every object update their velocities and register them with the gridcell they're in. Finally you loop through all the objects again to do collision detection and resolvement, but now you only need to check the objects in the occupied cell and it's neighbors.

__________________
Blog: Vipe Games updated 3 dec 2009
TOdorus is offline   Reply With Quote
Old 11-30-2009, 12:35 PM   #6
mordormaster
Registered User
Thank you very much il check them out, last question really, i have my object floor.enemy1.Inner_1 and i want it to hittest floor.map. How come it does the perimeter instead of the actual object?
mordormaster is offline   Reply With Quote
Old 11-30-2009, 01:04 PM   #7
rrh
Registered User
Because you're hitTesting two objects on each other and doing a full shape comparison could be a huge performance hit. You can get the full shape if you hitTest a point and an object.
rrh is offline   Reply With Quote
Old 11-30-2009, 01:19 PM   #8
mordormaster
Registered User
How would i do that then ive got the layers laid out for it now, ive fixed the ai chasing and patroling code now so if you could show me how to do that id appreciate it alot
mordormaster is offline   Reply With Quote
Old 12-02-2009, 06:34 PM   #9
mordormaster
Registered User
Une bump
mordormaster is offline   Reply With Quote
Old 12-02-2009, 07:38 PM   #10
rrh
Registered User
First you look up hitTest in the actionscript dictionary:
http://www.adobe.com/support/flash/a...ionary534.html

Pay special attention to any talk about the shape flag.
rrh is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:26 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com