Imparting Physics in only certain planes of motion

Newbie Unity user and first time poster, hello Unity community!

I have a WoW type camera, where you can move the camera around while it is always focused on one object. Instead of controlling the object directly though, they charge up a hit and release, much like what you would imagine for a mini-golf game.

I would like to allow the user to impart physics onto the ball on only the x and z planes, regardless of whether the camera is looking straight down at the ball from above, from directly under, or anywhere in between.

This is the current code for moving the ball, which allows the ball to be shot into the air.

projectile.velocity = transform.TransformDirection( Vector3(0, 0, power) );

I couldn’t find a similar question already asked after a good while of searching, so thank you in advance!

How about:

var dir = transform.TransformDirection( Vector3(0, 0, power) );
dir.y = 0.0;
projectile.velocity = dir;

Note you can also freeze the ‘y’ movement in the Rigidbody component of the projectile. In the Inspector, see the ‘Constraints’ section on the rigidbody.