0
\$\begingroup\$

Is there a way that even though two objects that have different y co-ordinate collide?
In my game, I wanted to make my object rotate as explained in previousquestion. When I added the code, the object now dissapears from the scene even though it's x and y co-ordinate are in the scene. I traced(in the function that kills the characer if it touches it. i.e hitt) the x and y value of the object and found that it is still there on the scene.
The code is:

ground.addEventListener(Event.ENTER_FRAME, hitt);

function hitt(event: Event) {
    if (green.hitTestObject(ground) || blue.hitTestObject(ground) || brown.hitTestObject(ground) || black.hitTestObject(ground)) {
        dead = true;
    }
    else if (kill.hitTestObject(black) || kill.hitTestObject(green) || kill.hitTestObject(blue) || kill.hitTestObject(brown)) {
        dead = true;
        trace("here",kill.y,green.y,green.x);
    }
}

The output is:

[SWF] hello.swf - 519178 bytes after decompression
here -608.95 -401 62.55

I don't know what's going on? Please Help..!!

\$\endgroup\$
0
\$\begingroup\$

The hitTestObject is not accurate at all. it will creates a rectangle from your both movieClips and then it will calculate the collision for those rectangle witch may be the parts of empty spaces of your movieClip.

you have to accurate your collision control by using hitTestPoint that detect hitTest between a rectangle of first area ( and that should be your bigger MovieClip ) and the point that you need to check for collision:

kill.hitTestPoint(black.x,black.y,true);//Find some sample for better understanding

Or for the best collision detection, you need to use hitTest of BitmapDatas. that will control the collision pixel by pixel. but its a little complicated.

see this : https://stackoverflow.com/questions/48906389/actionscript-3-alternatives-to-hittestobject-or-position-constraints/48956262#48956262

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.