# Collision detection for a player with walls.. ahh!

**URL:** <https://forum.kirupa.com/t/collision-detection-for-a-player-with-walls-ahh/226707>\
**Category:** Uncategorized\
**Created:** [May 23, 2007, 11:08am UTC](https://forum.kirupa.com/t/collision-detection-for-a-player-with-walls-ahh/226707 "2007-05-23T11:08:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imadingo](https://avatars.discourse-cdn.com/v4/letter/i/838e76/32.png) [@imadingo](https://forum.kirupa.com/u/imadingo)\
**Post date:** [May 23, 2007, 11:08am UTC](https://forum.kirupa.com/t/collision-detection-for-a-player-with-walls-ahh/226707/1 "2007-05-23T11:08:09Z")

</div>

I’m trying to code collision detection for my player and walls.  
I have the wall objects stored in an array, and I currently have my code so I have an event listener for enter\_frame on the stage. The function I have is this:

function onEnterFrame(event:Event){  
for(var i:int;i\<collisionObjects.length;i++){  
if(player.hitTestPoint(collisionObjects\*.x, collisionObjects\*.y)) player.bounceBack(collisionObjects\*);  
}  
}

The player’s bounceback code is what I need to code. I don’t know how to properly bounce back the player. The player has velocity x and velocity y, which update his position every frame. I tried sending the player back the opposite velocity for one frame, but that didn’t work as expected. How is this kind of situation normally resolved?? I also tried using hitTestObject but that had the same issue.
