Skip to main content
Inspiring
June 23, 2018
Question

How can I detect the collision with hitTestPoint ?

  • June 23, 2018
  • 2 replies
  • 980 views

I have a car game which is drive reverse.The game over when enemy and car hit each other.I have problem with collision. Car and enemy hit when they get close each other,but they have still big space in there.

Please check this image. https://s8.postimg.cc/p85w0wm2t/image.gif

Than somebody tell me I need to use "localToGlobal " So i do, i have a collision now,but it does when only contact to center of the object.Than said "You need to form a list (an Array) of border points and hit test all of them against the other object." But i can't figure out how.How can i do that ?

var aPoint:Point = new Point();

aPoint = carMC.localToGlobal(aPoint);

var bPoint:Point = new Point();

    bPoint = dubageri1.localToGlobal(bPoint);

var bir:Number=92;

var iki:Number=186;

var uc:Number=40;

var dort:Number=68;

var rakamlarlev8:Array=new Array("bir","iki","uc","dort");

stage.addEventListener(Event.ENTER_FRAME,ilkcikis);

function ilkcikis(event:Event) {

   

   

   

    var zHit:Boolean = carMC.hitTestPoint(bPoint.x, bPoint.y, true);

    textbaba.text = zHit? "! HIT !": "NO HIT";

   

   

   

trace(clickPoint);

   

    carMC.x=mouseX;

    carMC.y=mouseY;

   

   

}

This topic has been closed for replies.

2 replies

CemreBaou
Participant
August 6, 2018

grav = 0;

gravity = 2;

this.character.y += Object(root).grav;

Object(root).grav += Object(root).gravity;

while (this.ground.hitTestPoint(this.character.x, this.character.y, true)) {

this.character.y -= Object(root).gravity;

Object(root).grav = 0;

}

}
I use this command for gravity and they work with camera for Flash Player 26 but "hitTestPoint" is not working properly in "air 26 for Android". When camera moves, hitTestPoint is failing and causing the character to fall.
pleas help

kglad
Community Expert
Community Expert
June 23, 2018

first fix carMC's bounding box so it's limited to the visible object on stage.

KucuKekoAuthor
Inspiring
June 23, 2018
kglad
Community Expert
Community Expert
June 23, 2018

i'm not sure what that shows. but if your bounding box is precise and that's not good enough, use a shape-based hittest based on the bitmap hittest method.