"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

Launching rigidbody with force in the direction of the ARCamera's forward vector

Hey all,

I am developing an AR game that allows the player to launch a sphere at an image target.  When the player presses a button it adds force to the sphere's rigidbody component to launch it from its current position (which is directly in front of the camera).  My problem is that I cannot seem to get the ball to fire in the direction the camera is facing.  I have tried adding the force using the Camera.main.transform.forward * someVelocityValue but it doesnt seem to work.  I've also tried using AddRelativeForce but that's not working either.  The sphere begins its life as a child of the ARCamera until the moment the "Launch" button is pressed, at which time I parent it to the ImageTarget before adding force so that its movement is now relative to the image target (so if i move my camera I can see the ball traveling along its arc based on the force applied)

If you guys could help me figure out how to make my sphere always fire in the correct direction (the Vector3.forward value of the ARCamera) that would be great!




Wed, 06/27/2012 - 19:44

Figured it out, I had to use the Vector3.forward of the projectile's transform not the camera.  So, at start I instantiate the sphere with a rigidbody at a Camera.ScreenToWorldPoint coordinate (spawns the ball at bottom half of screen like a FPS gun) and then when the button to launch the ba