Hi
I have a basic targeting system whereby a canon shoots the player (3rd person). The canon should be shooting directly at the player, however it always shoots too high and I can’t figure out what’s causing this. I have tried tweaking multiple things but still no luck.
Help please!
========================================================================================
using UnityEngine;
using System.Collections;
public class Shoot_Gun : MonoBehaviour {
private float lastfired;
public GameObject cannon;
public GameObject player;
public int cannonRange;
public GameObject bullet;
public GameObject bulletSpawnPoint;
// Use this for initialization
void Start () {
lastfired = Time.time + 4;
}
// Update is called once per frame
void Update () {
/*
* every 4 seconds, check if the player is in range
*/
if (Time.time >= lastfired) {
lastfired = Time.time + 4;
//distance between cannon and player, within range
if (Vector3.Distance(cannon.transform.position, player.transform.position) <= cannonRange)
{
print("bang");
cannon.transform.LookAt(player.transform.position);
Instantiate(bullet,bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.rotation);
}
else {
print("not in range");
}
}
}
}
=======================================================================================