AddForce/ForceMode.Impulse

Hey Unity Answers Users…

I’m here today with a script and a problem. I need to find a way to add force to a projectile fired at another object. I need it to be in a curve fashion (Catapult Effect).

Here is my script:
#pragma strict

var sProjSpd : int;

var sProjDir : Vector3;

var targetP : GameObject;

function OnEnable()

{

targetP = GameObject.FindGameObjectWithTag("targetP");

sProjDir = Vector3.Normalize(this.transform.position);

}

function Update()

{
if(Input.GetKeyDown(“space”))

{
	transform.position = Vector3.MoveTowards(this.transform.position, targetP.transform.position, sProjSpd*Time.deltaTime);
}

}

Any help would be great. I have dabbled in putting addforce and forcemode.impulse but they seem not to work.

Regards,
Trent

To use rigidbody.AddForce successfully you must have a non-kinematic rigid body on the object and have no other scripts change the positional properties of the object. Multiply the direction with the impulse strength.