# Bounce effect using hitTestPoint

**URL:** <https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246>\
**Category:** Uncategorized\
**Created:** [July 6, 2008, 10:59pm UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246 "2008-07-06T22:59:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cF516](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cF516](https://forum.kirupa.com/u/cF516)\
**Post date:** [July 6, 2008, 10:59pm UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246/1 "2008-07-06T22:59:36Z")

</div>

im building a flash car game where if u hit the sides of the buildings you bounce off  
my problem is that sometimes you get stuck in the walls and it doesnt bounce at all

heres my bounce code

```auto

public function moveCar(timeDiff:Number) {

			
			// get current position
			var carPos:Point = new Point(gamesprite.car.x, gamesprite.car.y);
			
			// calculate change
			var carAngle:Number = gamesprite.car.rotation;
			var carAngleRadians:Number = (carAngle/360)*(2.0*Math.PI);
			var carMove:Number = speed*timeDiff;
			var dx:Number = Math.cos(carAngleRadians)*carMove;
			var dy:Number = Math.sin(carAngleRadians)*carMove;
						
			// see if car is NOT on the road
			if (!gamesprite.road.hitTestPoint(carPos.x+dx+gamesprite.x, carPos.y+dy+gamesprite.y, true)) {
					gamesprite.car.y = gamesprite.side.y;
					gamesprite.car.x = gamesprite.side.x;
					
		
				// see if car is on the side
				//bounce off
				if (gamesprite.side.hitTestPoint(gamesprite.car.x, gamesprite.car.y, true)) {
					gamesprite.y = (Math.sin(gamesprite.car.rotation * 0.018) * speed) * 5 / -1;
					gamesprite.x = speed * Math.cos(gamesprite.car.rotation * 0.018) * 4;
					speed = 0 - speed * bounce;
					
				}
			}
			
			// set new position of car
			gamesprite.car.x = carPos.x+dx;
			gamesprite.car.y = carPos.y+dy;
		}

```

heres a copy of the game  
[here](http://danberko.com/adam/gameV6c.swf)

can someone help me out plz

thanks

---

<div class="post-metadata">

**Author:** ![wvxvw](https://avatars.discourse-cdn.com/v4/letter/w/a9a28c/32.png) [@wvxvw](https://forum.kirupa.com/u/wvxvw)\
**Post date:** [July 7, 2008, 6:11am UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246/2 "2008-07-07T06:11:50Z")

</div>

you may check [Box2dflash](http://box2dflash.sourceforge.net/) library for that sort of things.

---

<div class="post-metadata">

**Author:** ![saxx](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@saxx](https://forum.kirupa.com/u/saxx)\
**Post date:** [July 7, 2008, 6:26am UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246/3 "2008-07-07T06:26:03Z")

</div>

Cool game, its like a cartoonish version of GTA2, keep going 🙂

---

<div class="post-metadata">

**Author:** ![cF516](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cF516](https://forum.kirupa.com/u/cF516)\
**Post date:** [July 7, 2008, 8:08pm UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246/4 "2008-07-07T20:08:45Z")

</div>

thanks, i cant figure this box thing out. its really annoying me

thanks for the response

---

<div class="post-metadata">

**Author:** ![cF516](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@cF516](https://forum.kirupa.com/u/cF516)\
**Post date:** [July 7, 2008, 11:14pm UTC](https://forum.kirupa.com/t/bounce-effect-using-hittestpoint/265246/5 "2008-07-07T23:14:46Z")

</div>

bump
