- Home /
Enemies Shoot Towards Face, Would Like to have them Shoot to Chest
So as the title states, when I get into range of my enemies, they shoot. That works perfectly fine, except for the fact that the bullets travel along a 45 degree angle by the looks of it and that's aimed at my head when I first get into range. The bullet continues to fire at the same angle and even the same direction. So it might be shooting in my direction, but when I jump to the other side of it, the bullet angle and direction does not change and it stays the exact same. This is my bullet code for finding the direction:
direction = PlayerScript.pPos - transform.position;
Which is put into the update function. Then when the player is in range, I call my Shoot function, and this is how I fire the bullet:
var firedbullet = Instantiate(bullet,transform.Find("EnemyBulletSpawn").position, Quaternion.Euler(direction.normalized));
I had the shooting working in another script, but I ran into a few problems, so I started cleaning it up and rewriting it. This shooting code is the exact same as the other one, but doesn't work like the other one does. Any help is very greatly appreciated. Thank you everyone.
Answer by Ben Ezard · Jun 19, 2012 at 02:51 PM
You could use transform.LookAt(target)
to make the bullets always move in the direction you want
I have it looking at the player when he's in range. It spawns from the spawn point, but it just doesn't correct it's direction.
Your answer
Follow this Question
Related Questions
Sidescroller Bullets Follow Mouse After Being Shot 2 Answers
Clones of enemies will not shoot 0 Answers
2D sidescroller ranged character shooting problem. 0 Answers
Code Converstion into javascript Help? 2 Answers
Finding Positions of other game objects and using them as an argument for an if statement. 0 Answers