x


Move instantiated object towards player's posistion

Hi

I have an object that is supposed to instantiate a sphere object and then shoot it towards the player's current position, i have an object that is taking the rotation of the player so that it always looking at them, I have the object instantiating but I have no idea what to do when it comes to applying velocity to the rigidbody.

Thanks

more ▼

asked Aug 02 '10 at 10:28 PM

Troy gravatar image

Troy
32 8 8 9

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

3 answers: sort voted first

You'll need to AddForce to the Rigidbody.

rigidbody.AddForce(transform.forward * 20); // tune '20' to control the velocity

Note that if you add this to Update(), it will accelerate (as the force is applied every frame).

Also, you've said it's taking the rotation of the player - that won't necessarily mean the object is heading towards them, it's just matching the rotation, so it will move parallel.

The object that spawns the Sphere object will need to Transform.LookAt the player position

more ▼

answered Aug 03 '10 at 06:35 AM

Marowi gravatar image

Marowi
4.9k 4 14 53

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

use:

transform.LookAt(Insert Player Position Here)

to look at your player, and:

rigidbody.AddRelativeForce(0, 0, 1); // Or whatever speed you want

to move forward

more ▼

answered Oct 26 '10 at 03:49 AM

fireDude67 gravatar image

fireDude67
945 9 15 30

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

you can use Vector3.forward of your shooter object.

more ▼

answered Aug 03 '10 at 05:50 AM

AliAzin gravatar image

AliAzin
2.5k 41 56 79

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

x3459
x2086
x576
x319

asked: Aug 02 '10 at 10:28 PM

Seen: 2206 times

Last Updated: Aug 02 '10 at 10:28 PM