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

Handling Collisions?

Explorer ,
Apr 12, 2013 Apr 12, 2013

Currently, I have a very very poor colision system. It's based off 4 points, if they hit an object, it stops me, if they don't, I can move freely. Simple right?

The issue is that these points don't cover my entire player object. I tried using a line, and it tweaked out and made it impossible to walk left (I'm working on my left collider before the rest). I also tried making a for loop that would handle all possible points between 2 given numbers (in this case 0 through -116.5). I don't think I initialized it correctly upon testing so it didn't work.

This is the check if I hit or not. True = hit, false = not hit.

var leftBumping:Boolean = false;

Here are my last 2 efforts:

var leftLine:Shape = new Shape();

leftLine.graphics.lineStyle(1,0x000000,0);

leftLine.graphics.moveTo(-26, 0);

leftLine.graphics.lineTo(-26, -115);

/**var leftBumpPoint:Array = new Array(leftP1, leftP2, leftP3, leftP4, leftP5, leftP6);

var leftP1:Point = new Point(-30, -55);

var leftP2:Point = new Point(-30, 0);

var leftP3:Point = new Point(-30, -25);

var leftP4:Point = new Point(-30, -75);

var leftP5:Point = new Point(-30, -195);

var leftP6:Point = new Point(-30, -116.5);**/

I have leftLine being used right now and it currently doesn't want to work correctly.

And the if/else statement to check:


if(back.collisions.hitTestPoint(player.x + leftLine.x+1, player.y + leftLine.y+1, true)){


leftBumping = true;

} else {


leftBumping = false;

}

(I have no idea why it's putting that code into a table)

What's a good way to handle this?

TOPICS
ActionScript
453
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 ,
Apr 12, 2013 Apr 12, 2013

if you want to use shape-based collision detection, use the bitmapdata class'es hittest.

in its most basic form, you create a bitmapdata object for each of the two objects you want to test and then use the hittest on those bitmapdata objects:

var bmpd1:BitmapData=bitmapdataF(mc1);

var bmpd2:BitmapData=bitmapdataF(mc2);

.

.

.

if(bmpd1.hitTest(bmpd2)){

//do whatever

}

.

.

function bitmapdataF(dobj:DisplayObject):BitmapData{

var bmpd:BitmapData=new BitmapData(dobj.width,dobj.height);

bmpd.draw(dobj);

return bmpd;

}

you'll need to do more than this basic example, because your bitmapdata objects will need to account for transforms of your displayobjects.

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
Explorer ,
Apr 12, 2013 Apr 12, 2013

I tried messing with this and couldn't get it to work.

However, I got my array working properly. But I just need to write a for loop to create all the points in the array (because making 117 points would be horrid)

I had this:

for(var i=0; i < 117; i++){


var p:Point = new Point(-30, i);

leftBumpPoint.push(p);

}

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 ,
Apr 12, 2013 Apr 12, 2013
LATEST

what's wrong with your code and/or what points do you want to add to leftBumpPoint?

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