I need to add force based on the angle I'm looking at the object.

Here, I’m using Unity’s add force script from the tutorial.


using UnityEngine;
using System.Collections;

public class MoveBox : MonoBehaviour
{
	public float pushForce = 1000;
	
	
	void OnMouseDown() {
		rigidbody.AddForce(-transform.forward * pushForce);
		rigidbody.useGravity = true;
	}
}

No matter where I’m looking at the object, (in first-person) it only adds negative force along the z axis (the blue arrow). How can I change this, so it will add force forward from where I’m looking at it.

Try with:

Vector3 direction = (transform.position + transform.forward) - transform.position;
rigidbody.AddForce(direction * pushForce);

Note this is just doing:

Vector3 direction = transform.TransformDirection(Vector3.forward);