I can’t seem to get this to work, what I’m trying to do is get the gameObject to add force in the direction of the hit point of the raycast which is being casted from the mosue position, however nothing I have tried so far works. Here’s my code:
if (Input.GetButton ("Fire1")) {
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, Mathf.Infinity)) {
var newVector3 = hit.point;
var moveDir = transform.position - newVector3;
rigidbody.AddForce (moveDir * speed);
}
}