- Home /
My bullet follows my plane...
I have a plane that shoots a bullet in 2d. One is called plane and the other called bullet! That simple! When I hit the space bar the bullet fires. If I hit the space bar and then move the plane the bullet playing its "bullet fire" animation the whole animation with the bullet moves:( I want the bullet to fire stay in one spot when the plane moves and hit something. But plane moves bullet moves... How can I fix this? Here are my codes...
This is the bullet's code...
function Update()
{
if(Input.GetButton("Jump"))
{
animation.Play("Bullet Fire");
}
}
Now here is the code for the plane...
function Update()
{
if(Input.GetButton("Fire2"))
{
//do something
transform.position.x += 0.3;
}
else if(Input.GetButton("Fire1"))
{
transform.position.x -= 0.3;
}
}
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == "enemy")
{
Destroy(gameObject);
Destroy(col.gameObject);
}
}
Thanks for helping!
Answer by Kiloblargh · Oct 29, 2013 at 04:02 PM
The answer should be obvious. You have the bullet animation attached to the plane and you are animating the bullet relative to the plane. You can't do that. You need to instantiate bullets. ( Actually instantiating bullets is never good practice, so you need an object pool but get a clue first and then worry about performance optimization. )
Your answer
Follow this Question
Related Questions
My bullet wont move forward 1 Answer
Gun Script Error (Fixed!!!) 1 Answer
Accessing Coroutine from another Script? 1 Answer
Main menu camera change script. 1 Answer