x


How to spawn an object with an added force

How can I spawn an object and add force onto it?

Thank you for your time!!!

more ▼

asked Jun 01 '11 at 05:37 PM

EytanTKing gravatar image

EytanTKing
24 9 13 21

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

1 answer: sort voted first

Just make a variable for example bullet and it has to be of type transform and then use this code inside your function. You also have to make a spawnpoint, were you want the bullet to appear.

var bulletPrefab : Transform;


    var bullet = Instantiate(bulletPrefab,transform.Find("SpawnPointCannon").transform.position, Quaternion.identity);

// this applies a force to your bullet 

bullet.rigidbody.AddForce(transform.forward * 1000);
more ▼

answered Jun 01 '11 at 05:43 PM

BarkShark gravatar image

BarkShark
281 13 17 24

(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:

x5099
x441
x329
x245

asked: Jun 01 '11 at 05:37 PM

Seen: 894 times

Last Updated: Jun 01 '11 at 05:43 PM