- Home /
Bullet not moving
I created a script so that when the player pressed the left mouse button, it would put a bullet out. It works. I created a prefab and it is circle. I put this script and the problem is that if I press the left button, it does go out but it doesn't move. Could you help me with my script?
//Make it into trigger.
Function OnUpdate ();
// Destroy object incase it goes on and on
Destroy(gameObject. 3);
//Keep this going
Vector3.moveObject
//Make it spawn at gun.
position.transform(Find.gameObject("Gun");
Function OnTriggerEnter (enemy:Collider);
// Destroy object when it hits enemy to avoid multiple damage
Debug.Log("Trigger is on");
if(other.gameObject.FindWithTag("enemy");
Debug.Log("It hits enemy.");
Destroy(gameObject);
have you added a force to a bullet? or have you done anything to move the bullet?
Answer by Landern · Nov 29, 2012 at 01:53 PM
First, this question is.. i swear asked daily, a simple search for bullet on unity answers/forums will give you so much information, but its all pretty much the same, but it's already been answered over and over and over and over .. ad nauseam.
Now..
If you have a rigidbody attached to the bullet, this gives the game object the capabilities of automagical physical, i know that sounds all great and awesome, but, having the rigidbody doesn't mean any force(s) are applied, so you have to give it the force of forward momentum. This is done with a single line in the script.
Without the rigidbody you will need to control the game object transform position by hand, through the script, otherwise, yes, the bullet(or whatever) will just sit there.
But really, check out the search function, it's METAL!! and by that, i mean you will find all the information.
@DeveshPandey: Thank you
@Jodhale: besides the documentation, which is important to understand, using the search features of the site will extend you knowledge further because most standard/normal/fps questions have been asked over and over, there are many examples and tutorials available, enjoy.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Spawn Script Not Working 1 Answer
Problem creating a 2D scroller shooting game 2 Answers
Main Menu Problem 0 Answers