Search code examples
flashactionscript-3actionscriptpapervision3d

Papervision 3d hitTestObject doesn't work?


I'm new to papervision 3d and I created two display objects in basic view.
Here's a part of the code :

...
_stick = new Cube(materials, 50, 5, 500);
_ball = new Sphere(new ColorMaterial(0xfc0000), 80);

In the onRenderTick method, I tried to check whether two objects are hitted

override protected function onRenderTick(event:Event=null):void {
    super.onRenderTick(event);
    _stick.rotationY = stage.mouseX / stage.width * 360;
    _stick.rotationX = stage.mouseY / stage.height * 360;

    if (stick.hitTestObject(this.ball)) {
        trace ("hit");
    }
}

However, stick.hitTestObject always returns false even if the stick really hits the ball as I see in the flash.

Any help is appreciated ~ Thanks!


Solution

  • A long while back I worked around a similar issue by using an API I found somewhere in P3D that transforms from 3D to 2D (screen) coords. So I added a regular button on top of the 3D visuals, and each frame I moved the button to center on the screen location of the 3D hit area. But this only worked because I didn't need the hit area to transform - I never got "real" 3D hit areas to work in Papervision3D. And since that project is apparently orphaned, I wouldn't suggest spending a great deal of time on it if you can help it.