Collision Detection - actionscript-3

i am working on a project that needs some collision detection.
i have 7 objects and it should check collide for each others.
i looked collision detection kit by Corey O'Neil, but cant figure it out.
collision group i have to learn, yes.

You should understand your needs.
hitTestObject method will work fine if you have no FPS drop and object is static or have small speed.
Else you better to use one of Physics Engine or CDK like a Box2D for correct collision detection and make your Update method fixed timestep.

Try hitTestObject()
if(object1.hitTestObject(object2))
{
// collision was detected, do stuff here
}

Related

Collision filtering in libgdx using Liquidfun

I successfully implemented liquidfun extension in my libgdx/box2d project, but the particles that are created in the box2d world doesn't seem to collide with anything at all when used in my project. The test code given with the setup works good in the way that it collides with the rigid bodies.
I actually want to know any way that collision filtering can be done between the particles and rigid bodies here. Apparently categorybits/maskbits do not work here. Please Help!

LibGdx collision (wall)

I want to get the effect of "the wall", something like the walls of the maze.
if(gameObject1.overlaps(gameObject2)){
}
GameObject1 is moving and GameObject2 is to be wall. How to do it?
Define both objects (moving and wall) as Rectangles (or set of Rectangles).
Now you can use n^2 overlapping test on all of them.
You need to implement appropriate collision response once the collisions are detected.
This would include disabling motion in that direction. You can do it using flags for each direction.
Alternatively, you could use a physics engine and let it handle the collision handling completely.

Best way for draggable objects collision detection with complex objects

I'm having a difficult time figuring out having objects with multiple bounds for a drag-able object. HitTest isn't working because when dragging fast, the object will overlap before HitTest fires. I was wondering if there was a more efficient way for figuring out this interaction.
I'm going to try to store each rectangle x,y,width,height, and then loop through those, to figure out if the object has touched and stop the player from being draggable in that direction.
Because you are trying to detect collisions happening at high speeds, you need to use some form of swept-polygon collision detection. Sampling collision at only one time between the previous and the last frame will always have a chance of failing.
Check out this brief explanation of Swept Collision detection:
http://howlingmoonsoftware.com/wordpress/?p=300
Or just do a search for "swept collision detection"
If you are doing this in a game, you might also find using a library like Box2D would be a worthy solution to the problem. In Box2D parlance what you want is continuous collision detection.
http://www.box2d.org/manual.html

Hit testing for a maze

I am making a maze game and i have the edge of the maze as a movieclip. I'm trying to test if the player hit tests the maze to make him stop using this code.
If(player.hitTestObject(Maze))
{
function()
}
But wether or not It's actually touching the maze (it's in the empty space on the inside) it always registers as touching. Is there any way to fix this?
You won't have to use any physics api. They are too heavy and complex and your task is simple. Try replacing your hitTest method for hitTestPoint
if(Maze.hitTestPoint(player.x,player.y))
{
function()
}
Cheers!
This is what you're looking for:
http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/
The reason why hitTest always says true, is that it only checks to see if the bounding boxes for the two objects touch each other. More nfo on what that means can probably be found in the link above. What is in the link above, is an explanation of how to do pixel-perfect hit tests in flash. :) Also if you're doing a game using collision like this and/or any kind of physics, you may be interest in this tutorial:
http://gotoandlearn.com/play.php?id=135
It's a video about a world construction kit for Box2D, probably the most popular physics library for flash.

Flash CS4 / AS3 symbol within symbols

I'm trying to create a multi-level dungeon adventure in Flash CS4. The layout is an instance created of a symbol called Level, within the symbol are multiple wall subsymbols (wall), instances of Wall. There is a collision routine to stop the player walking through the walls, called from Wall.As.
Level is drawn about the centre point (0,0).
When I create an instance on the stage of Level (level), the collision tester is using the xy coordinates for the walls drawn about 0,0, not the "real" xy where it's appearing on the stage.
So what I need to know, is how to "update" the xy for each wall subsymbol with the live stage information, overriding the XYs drawn in the parent. It has to be updated unfortunately (I can't keep it static), as the levels are big so have to scroll.
Thanks for your advice.
With all due respect forget your approach, you're reinventing the wheel for nothing and probably to end up getting worse performance. What you need is pixel-perfect collision detection and probably including basic physics so already we're talking a huge amount of work. If you want to build levels in a design way for a game, use this, it'll blow your mind how awesome/easy/cool this is:
http://www.gotoandlearn.com/play.php?id=135
Its always a guess when trying to answer questions like this, as there are a lot of unknowns. That being said, in programming, there are always more than a few ways to solve a problem. Examine your collision detection routine - if you worked with hitTestPoint, and the point that was being tested (mouseX,Y or your main actor) with localToGlobal, you likely wouldn't need to test for the x,y variables of your collision objects. Read up on those two subjects and this question might be rendered moot.
At any rate, you could update relative coordinates in your Wall.as instance by leveraging globlaToLocal:
public function get curLoc():Point
{
return globalToLocal(new Point(this.x, this.y));
}
and retrieve them from your parent class as a point you can then test against:
trace(_wall.curLoc);
Hope that helps
I suppose you could accomplish what you're trying to do by manipulating the transform property of the wall symbols, but honestly I would concur with Ascension Systems and just abandon your collision testing routine for something different.
You may not need to go all out with a physics engine for your game, in which case just use hitTestObject to do the collision detection.