Basic Targeting System - Canon shooting too high

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");
		}
	}
}

}

=======================================================================================

Sounds like one of your pivots is in the wrong place, either the pivot of your player is too high or, more likely, the pivot of your cannon is below the barrel.

You could try moving the pivot(s) up or down respectively (either in your modelling program or with this handy script http://unifycommunity.com/wiki/index.php?title=SetPivot )

The other method would be to use cannon.transform.LookAt(player.transform.position + Vector3(0,offset,0)); , where offset is a corrective (negative) value to get your cannon pointing in the right place.

Thanks man, that did the trick!