- Home /
How to stop enemies from shooting each other
Okay so I'm making a 2D video game in the style of Space Invaders, but I'm having an issue where the enemies on the top row shoot those on the lower rows. I honestly don't know how to stop them from shooting. I have considered raycasting, but I haven't used that in a long time, and never on a 2D product. My current script controlling when they shoot looks like this:
#pragma strict
var enemyShot : Transform;
var shotTime = 1000;
var timeToShot = 0;
function Start () {
}
function Update () {
timeToShot ++;
if (timeToShot == shotTime){
Instantiate(enemyShot, transform.position, transform.rotation);
timeToShot = 0;
}
}
Post your targeting script.. The script you posted doesn't show it's target acquisition stuff.
That's because they don't really target. They just kinda shoot straight down, in the general direction of the player, and hope they hit something. Surprisingly effective.
"I have considered raycasting"..
That's exactly what you should do.
Post comments as comments. I'll convert this one for you.
Your answer
Follow this Question
Related Questions
Can someone help me to understand why this raycast is not working properly? 1 Answer
Problem with raycasting in direction of mouse 0 Answers
Raycast shooting in the middle of the screen 1 Answer
scripting problem 0 Answers
fps shooting enemy 1 Answer