0
votes

Hey I am beginner Flash Action Script 3 developer.

I am using hitTestPoint() to detect collision between a car and a stage drawing. Car is moving in the stage so I am using hitTestPoint().

There is a problem, Lets say.

Car is a square, it is actually a perfect square right now.

I am doing this:

heightHalf = car.height / 2;
widthHalf = car.width / 2;

if(level.hitTestPoint(car.x + widthHalf, car.y + heightHalf,true)){
    trace( "Right Collision" );
}

It should work as, car.x + the half of its with should return the point on x-axis which is colliding and same with the y-axis. But its not working.

When my car collides with the right walls it doesn't produce error or trace, but If I move my car further out of stage(as car can go through walls) just before it can completely move out, it produces trace error just when left side is colliding with walls.

These pics should help:

Right Collision with no error: http://i.minus.com/ibqvrbNHuLTTIX.png

Error but with wrong side: http://i.minus.com/iGRNRVmCwwY4x.png

Inverting the + - signs isn't helping either.

1
Where is the registration point for your car movieClip? Are you definitely wanting to hitTest a single point (essenitally a pixel) rather than the whole car? - dan-steel

1 Answers

0
votes

Take notice to where the anchor point is on the car object. since you are using Flash IDE, The anchor point could be in the middle, right, or left corner.

Also you will need multiple points do to this type of hitTesting. at least one for each side of car.

If your registration point is top left, then you are hitTesting the middle point of your car. So it will only register collision when half of the car goes over the wall.

Check your registration point. When you create a new movieClip or Sprite you can select the registration point by clicking one of the 9 box on the square that comes up under the name of the Object.