x


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

more ▼

asked Mar 23 '12 at 07:28 AM

castleforce gravatar image

castleforce
31 6 6 9

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 23 '12 at 04:11 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1367
x253
x244
x9

asked: Mar 23 '12 at 07:28 AM

Seen: 1315 times

Last Updated: Mar 23 '12 at 04:11 PM