# Collision Detection Kit and player

**URL:** https://forum.kirupa.com/t/collision-detection-kit-and-player/317846
**Category:** programming
**Created:** [January 4, 2011, 4:15pm UTC](https://forum.kirupa.com/t/collision-detection-kit-and-player/317846 "2011-01-04T16:15:50Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Antago](https://avatars.discourse-cdn.com/v4/letter/a/c77e96/32.png) [@Antago](https://forum.kirupa.com/u/Antago)
#### Post date: [January 4, 2011, 4:15pm UTC](https://forum.kirupa.com/t/collision-detection-kit-and-player/317846/1 "2011-01-04T16:15:50Z")

</div>

I’m trying to use Cory Oneil’s [**Collision Detection Kit**](http://www.coreyoneil.com/portfolio/index.php?project=5) for managing collisions. The problem I am coming across is I will be having a lot of different objects that collide with each other.

Naturally, the **CollisionGroup** class is the right choice. I want to test collisions of a specific object moving with any number of speeds in the X and Y axis, and then control its movement based on that. So, in the main movement function of the object I am setting the _forceX_ and _forceY_ of the object. I am then checking for collisions and attempting to make the object move accordingly.

```auto

		private function Walk() : void
		{
			for ( var i:uint = 0; i < 4; i ++ )
			{
				if ( key[i] == true
					 && dir != i
					 && ( oldkey[i] == false || key[dir] == false) )
					dir = i;
			}
			
			if ( dir == 0 || dir == 2 )
			{
				forceX = 0;
				forceY = ( key[2] - key[0] ) * speed;
			} else
			{
				forceX = ( key[3] - key[1] ) * speed;
				forceY = 0;
			}
			
			var collisions:Array = collision.objectCollisions( _block );
			
			if ( collisions.length )
			{
				var collisionInfo:Object = collisions[0];
				
				var angle:Number = collisionInfo.angle;
				var overlap:int = collisionInfo.overlapping.length;
				
				var sin:Number = Math.sin( angle );
				var cos:Number = Math.cos( angle );
				
				var vx0:Number = forceX * cos + forceY * sin;
				var vy0:Number = forceY * cos - forceX * sin;
				
				forceX = vx0 * cos - vy0 * sin;
				forceY = vy0 * cos + vx0 * sin;
				
				forceX -= cos * overlap / 5;
				forceY -= sin * overlap / 5;
			}
			
			x += forceX;
			y += forceY;
		}

```

Basically, I am drawing a rectangular object defining the size of the object. I am applying the _forceX_ and _forceY_ to the object at the end of the function. The object known as “\_block” is a simple rectangular sprite. The problem is that all of the examples I’ve seen so far for **CDK** use small perfect, falling, side-view spheres. My objects will be moving any direction and their “\_block” will be any shape.

This is not working. Instead the objects are jumping a little and sometimes going through objects. It’s really buggy.

Is there anyway to make objects that move in any direction on the X and Y axis in any shape collide with any shape and perfectly stop on pixel-perfect collision? Any good examples with **CDK**?

**Note:** To reduce processing, I created a function inside of **CollisionGroup** class which merely returns an array of collisions to a specific object rather than an array of \*all collisions \*with _all objects_, as you see in my code **collision.objectCollisions( \_block );**.
