2

I am building a game that launches a ball at a target(Plane). The Plane is rotated back 45 degrees. I want to convert the global ball position(x,y,z) into the local coords of the target so I can detect where it hits.

Any ideas?

Boyd
  • 1,169
  • 8
  • 14

2 Answers2

4

Use the target plane's inverseSceneTransform to transform the position vector of the ball. That should do it.

var localPosition : Vector3D;
localPosition = plane.inverseSceneTransform.transformVector( ball.position );

That should give you the ball's position in the plane's local space.

richardolsson
  • 4,041
  • 1
  • 17
  • 19
  • Thanks so much! Are you one of the developers on away3D? I think I have seen your name before on the away3D forums. – Boyd Aug 28 '11 at 14:56
2

Above solution only works if the item/ball is directly on the stage. If it isnt, you should use ball.scenePosition!

item.position = targetContainer.inverseSceneTransform.transformVector(item.scenePosition);
bradbury
  • 51
  • 4
  • 2
    Developing witch away3D is extremely tedious, since not even the official answers from their developers are 100% useable! If I had to start the project anew, I'd force my boss to buy Flare3d instead of using Away3D. It isn't saving if a free library costs you double the development time in the long run. – bradbury Oct 01 '12 at 13:44