- Home /
Bullet does not move forward
i have written code for firing bullet. but it does not move forward. when my bullet is instantiated, It appears infront of my gun. So what can be the problem? pleaze help me,.
Here is my code:
#pragma strict
var BulletPrefab : GameObject;
function Update () {
}
function OnGUI()
{
if(GUI.Button(Rect(10,10,90,50),"Fire"))
{
var bullet : GameObject;
bullet = Instantiate(BulletPrefab, gameObject.Find("Spawn").transform.position , gameObject.Find("Spawn").transform.rotation);
//bullet.rigidbody.AddForce(bullet.transform.forward * 5000);
bullet.rigidbody.useGravity = false;
bullet.rigidbody.AddForce(bullet.transform.forward * 5000 , ForceMode.Impulse);
}
}
please solve my problem. Thanks for your help and support in advance.
Answer by kramcomposer · Mar 04, 2013 at 07:44 AM
Your Code Looks Correct.. only 3 things I can think of Are: Your Bullet prefab / or GameObject rigidbody is Marked as Kinimatic
you Bullet's rigidbody is marked to freeze on certain axis
Time.timeScale = 0? Make sure its = 1 to see if your script is working
thanks. Actually i have not added rigidbody component. But now its works.
Your answer
Follow this Question
Related Questions
Bullet does not move forward after being initiated 1 Answer
Basic Shooting Game 1 Answer
Only one of all my Enemies shoots, Help please. 1 Answer
Timing Between each Gun Shot 2 Answers
Shooting & Animation Problem 1 Answer