- Home /
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
Answer by · Aug 03, 2010 at 06:35 AM
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
Answer by fireDude67 · Oct 26, 2010 at 03:49 AM
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
Your answer
Follow this Question
Related Questions
How do I make rigidbody.velocity in local space? 1 Answer
NullReferenceException in follow function 0 Answers
Dragging object out of position 2 Answers
Get Vector3 position of player? 0 Answers
Need help with building system 1 Answer