- Home /
Problem with shooting an object in 2D
Hi there,
My problem is that when I spawn an object and the shooting script on it is called, which should accelerate the object itself the moment it spawns, nothing happens. Here is the shooting script attached to the bullet (I want the bullet to fly in the direction of the player):
public float speed = 1f; public Transform player; private Vector2 dir;
// Use this for initialization
void Start ()
{
dir = player.transform.position - gameObject.transform.position;
gameObject.transform.Translate (dir.normalized * speed * Time.deltaTime);
}
Answer by AmirBraham · Oct 15, 2016 at 03:03 PM
Just change "void Start" to "void Update" The start method is only called once , that's why your gameobject isn't moving however Update is called every frame
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
How do i maintain the same speed in the air? 1 Answer
Box goes through walls 2 Answers
Connecting my 2 Scripts 1 Answer
Smoothly move 2D Sprite 2 Answers