[SOLVED] Picking the object in the center of the view (basic for FPS shooter)

Software: Away3D 4.x

Mario M., Newbie
Posted: 23 August 2013 01:24 PM   Total Posts: 12

I’ve seen a lot of examples of picking objects with mouse, but none of picking by view coordinates.
I need it for a shooter game that will be played only with keyboard, so the centre of the view will be the crosshair.

I’ve tried to find where the mouse coordinates are translated to a ray with no luck. Any clue where to look for?

I need something similar to View3D.getObjectsUnderPoint(x,y), but with the same behaviour and precision as MousePicking.

Any idea?


LAST MINUTE NOTE: I’ll try with RaycastPicker.getViewCollision

   

Mario M., Newbie
Posted: 23 August 2013 01:48 PM   Total Posts: 12   [ # 1 ]

RaycastPicker.getViewCollision is working!

But I have an aditional problem, objects I wan’t to detect has alphaBlended textures and collisions are hitting also in transparent areas. PB_FIRST_ENCOUNTERED (PixelBender-based picking collider) is not working, maybe it’s not related to alpha-bending.

The workarround I’m thinking is to create a more adjusted ghost mesh for collisions.

Any other solution?

   

Mario M., Newbie
Posted: 24 August 2013 06:13 PM   Total Posts: 12   [ # 2 ]

Still trying to detect the collision on planes with alphaBlended textures.
I already have the uv coordinates to check if picked color is transparent.

First I needed to activate pixelblender detection:

mesh.mouseEnabled = true;
mesh.pickingCollider = PickingColliderType.PB_BEST_HIT;
mesh.shaderPickingDetails = true;
mesh.geometry.convertToSeparateBuffers();

Anyway I already had a problem, because I was also using an animated SpriteSheetMaterial that uses different ScaleUV and OffsetUV in every frame, and UV coordinates given by PBPickingCollider.testSubMeshCollision doesn’t takes this params (UV values were allways relative to tho whole spritesheet, not the current frame portion).

I needed to path this issue (that maybe should be solved), by transforming _pickingCollisionVO.uv taking current animation frame values:

public function isTouchingSolid(mesh:Mesh, uv:Point):Boolean
{
var frame:SpriteSheetAnimationFrame = SpriteSheetAnimator(mesh.animator).frame;
var uvTransform:Matrix = new Matrix();
uvTransform.identity();
uvTransform.scale(frame.scaleU, frame.scaleV);
uvTransform.translate(frame.offsetU, frame.offsetV);
uv = uvTransform.transformPoint(uv);

var bmd:BitmapData = BitmapTexture(SpriteSheetMaterial(mesh.material).texture).bitmapData;
var x:uint = uint( bmd.width * uv.x );
var y:uint = uint( bmd.height * uv.y );
var color:uint = bmd.getPixel32(x, y);
return color != 0; 
}

New issue submited in GitHub:
https://github.com/away3d/away3d-core-fp11/issues/630

   
   
‹‹ Scene resize problem

X

Away3D Forum

Member Login

Username

Password

Remember_me



X