How can I apply force in the direction of the camera when the user presses the mouse

Is there a way to, when the person presses the mouse button, apply force in the direction the camera/ object is facing? I have the adding force part, i just need it for the direction the object is facing.

Yes, all GameObjects (including cameras) have a transform component, and on the transform class is a .forward variable which indicates the forward direction of that object as a vector.

So, for the main camera's direction, just use this as the force direction vector:


Or for any other object:


Or for the forward direction of the object that the script is on, simply:


Multiply it by whatever you want to control the strength.

As an example, you could place this script onto any object that you would like to be "pushed" when clicked on:

var forceStrength = 50.0;
private var applyForce = false;

function OnMouseOver() {
    if (Input.GetMouseButton(0)) {
        applyForce = true;
    } else {
        applyForce = false;

function OnMouseExit() {
    applyForce = false;

function FixedUpdate() {
    if (applyForce) {
        rigidbody.AddForce(Camera.main.transform.forward * forceStrength);

Any gameobject with this script attached (and which has a rigidbody) will be "pushable" with the mouse, and will be pushed in the direction of the camera's forward vector.