I’ve been trying to get an enemy to fire a projectile from a spawn point, and while it’s firing in the right direction and at the right speed, the height is way off and I don’t know what’s causing the problem.
Here’s a picture of what’s going wrong as well as some code. Note that GameObject SpawnPoint has its value assigned via the Inspector panel.
using UnityEngine;
using System.Collections;
public class RedNinjaCat : MonoBehaviour
{
//create a timer that determines how often an arrow is fired
int arrowTimer = 0;
int health = 1;
public Transform ShurikenDrop;
public Transform KunaiDrop;
public Transform MouseDrop;
public Transform CatnipDrop;
public Transform FoodDrop;
public Transform FishDrop;
public Transform ArrowShoot;
public GameObject SpawnPoint;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
arrowTimer++; //increase the timer
if (arrowTimer == 120) // Every 2 seconds (120 frames)
{
arrowTimer = 0; //reset the timer
Transform instanceBullet = (Transform)Instantiate(ArrowShoot,
SpawnPoint.transform.position, SpawnPoint.transform.rotation); //Create the arrow
}
if (health <= 0) {
enemyDie ();
}
}