Error problem with addforce

Hello i have a problem with my script. Trying to add force to this gameobject when i shoot it with my raycast. And it will move AWAY from the player (where the raycast it casted from). But i get a nasty error:
“Operator ‘-’ cannot be used with a left hand side of type ‘UnityEngine.Transform’ and a right hand side of type ‘UnityEngine.Transform’.”


 #pragma strict
 var rb : Rigidbody;
 var force : float;
 var PlayerPosition : Transform;
 var HittedObjectPosition : Transform;
 function AddForceFunction ()
     rb.AddForce(PlayerPosition - HittedObjectPosition).Normalized * force;

You cannot subtract transforms. You want to subtract their position.

rb.AddForce((PlayerPosition.position - HittedObjectPosition.position).Normalized * force);

That said, you should really consider looking into what a Force is and rename a few things.

Firstly, force is naturally a Vector. It has direction and magnitude. Second, you’ll want to likely change your ForceMode to Impulse, as you’re calculating an instantaneous resultant force. Your solution will likely need:

rb.AddForce((PlayerPosition.position - HittedObjectPosition.position).Normalized * force, ForceMode.Impulse);