Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hit side detection.

Explorer ,
Feb 11, 2017 Feb 11, 2017

Is there a way to determine which side of the object was hit top, left, right, bottom ?

I don't wanna to overlap each other the objects.Also I wanna keep the objects in stage limit.The buttons must move away when hit each other.

How do I move the object to reverse direction when hit each other ?? for example: Fish 2 hit below or top from to fish 3,then fish 2 go y.if Fish 2 hit to fish 3 from left or right side then fish 2 go x.How can I do that ?

I add red rule for hit but buttons moving like a stuck.Also I tried hitTestObject but move stuck again.I have 7 object on the stage.

I use this code move for sample object.

var fish2x:Number=8;
var fish2y:Number=8;

stage
.addEventListener(Event.ENTER_FRAME,h42);
function h42(s:Event) {
fish2
.x+=fish2x;
fish2
.y+=fish2y;
if ((fish2.x>=stage.stageWidth-fish2.width/2)|| (fish2.x <= fish2.width/2 || (fish2.x <=fish3.y/2))) {
  fish2x
*=-1;
}
if ((fish2.y>=stage.stageHeight-fish2.height/2)|| (fish2.y <= fish2.height/2 )) {
  fish2y
*=-1;
}

bandier.gif


TOPICS
ActionScript
244
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2017 Feb 11, 2017
LATEST

there's no quick way to do that.  you would need to know (or determine) each objects registration point and then use that info to determine its left boundary and top boundary etc.

i created a  pseudo-3d app that needed all that info (and more) in the dock designer here, Dock Builder

you can see how the boundaries of dock pieces are used when you try to overlap two dock elements.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines