- Home /
My instantiated projecttile refuses to move
var Missile : Rigidbody;
var localOffput : Vector3 = new Vector3(200, 200, 200);
var SpawnPlace : Vector3 = new Vector3(0, 0, 0);
var startingSpeed : int = 30;
function Update () {
SpawnPlace = new Vector3(transform.position.x, transform.position.y, transform.position.z);
}
function Blast () {
Debug.Log("I'M FIIRIN MY MISSILWE!!!");
var newMissile : Rigidbody;
newMissile = Instantiate (Missile, Vector3(transform.position.x, transform.position.y, transform.position.z), gameObject.transform.rotation);
//PlayerSpeed = transform.Find("Capsule");
//newMissile.rigidbody.velocity = GameObject.Find("Wings").rigidbody.velocity;
//newMissile.angularVelocity = GameObject.Find("Wings").rigidbody.angularVelocity;
//newMissile.velocity += transform.TransformDirection(Vector3.forward * startingSpeed);
newMissile.rigidbody.AddForce(transform.forward * startingSpeed);
//newMissile.velocity += transform.TransformDirection(Vector3 (0, 0, startingSpeed));
//newMissile.velocity = new Vector3(300, 300, 300);
Physics.IgnoreCollision(newMissile.collider, transform.root.collider);
}
OK, I have no idea why my instantiated missile refuses to move, no matter what kind of code I put on it. In fact, it does not seem to at all be affected by anything I code after I instantiate it. What could cause such a behaviour? What have I forgot to do?
... Why cannot I modify my question to correct the word "projecttile"..? Or is it simply that I cannot detect the means of doing so..?
Swii... It does not even ignore collisions, despite that last row of code...
Answer by loopyllama · May 12, 2011 at 08:30 AM
you are adding a force on a single frame and I bet it is working. It is just a very small force. Try making your startingSpeed number very large. Perhaps you should control the movement by adding a small amount to the position each frame rather than use the physics system.
using the physics system to move a rocket is like opening a bag of chips with a sledgehammer. yes, it will indeed work.
Answer by Antony-Blackett · May 12, 2011 at 08:35 AM
Try changing the AddForce line to this.
newMissile.rigidbody.AddForce(transform.forward * startingSpeed, ForceMode.VelocityChange );
Your answer
Follow this Question
Related Questions
Make multiple Projectiles move at the same Time... 0 Answers
Multiplayer Projectile Instantiation 1 Answer
Scripts not on instantiated GameObjects? 1 Answer
Rotating and firing projectiles 1 Answer
Slow automatic shooting script? 2 Answers