Why don't my laser shots shoot from the same position consistently?

I have a little robot guy that jumps up and down and he shoots lasers out of his eyeballs when a button is clicked. I used the unity project ‘Space Shooter’ to help aid me in designing the code. The problem is that there seems to be a delay sometimes and it doesn’t appear that the lasers are coming out of his eyeballs but a little lower or higher depending on what position he is in his jump. I nested the shotSpawn gameObject underneath my Player gameObject and positioned the shotSpawn right on top of the eyeball, so what is the problem?

Here is my RobotController script:

using UnityEngine;
using System.Collections;

public class RobotController : MonoBehaviour
	public float height;
	public float verticalSpeed;
	public float horizontalSpeed;

	public GameObject shot;
	public GameObject shotSpawn;
	public float fireRate;

	private float nextFire;

	Animator animator;

	void Start ()
		animator = GetComponent<Animator>();

	void Update()
		if (Input.GetMouseButtonDown (0) && Time.time > nextFire) 
			nextFire = Time.time + fireRate;
			Instantiate (shot, shotSpawn.transform.position, shotSpawn.transform.rotation);
			audio.Play ();

	void FixedUpdate ()
		Vector3 pos = transform.position;
		pos.z = -2;
		transform.position = pos;

		Vector3 direction = Vector3.zero;
		direction.x = -Input.acceleration.x*horizontalSpeed;
		if ( direction.sqrMagnitude > 1 ){
		direction *= Time.deltaTime;
		transform.Translate( direction * verticalSpeed );

		// Smoothes the rotation when touching Box collider... not sure why
		rigidbody.constraints = RigidbodyConstraints.FreezeRotation;


	void OnCollisionEnter(Collision collision){
		foreach(ContactPoint contact in collision.contacts){
			rigidbody.velocity = transform.up * height;


Here is my Mover script:

public class mover : MonoBehaviour 
	public float speed;

	void Start()

		rigidbody.velocity = (transform.up + transform.right) * speed;



Where are you setting fireRate? As a test you can take that check out and just instantiate whenever the mouse button is clicked to narrow issues down.


the “laser shooting position” will need to be a child of THE HAND - or something like that.

very simply, look using your eyeballs at the editor as it is playing. click on the “laser shooting position” game object, and watch if it goes up and down with the “hand” or whatever is relevant.

if not, move one object inside the other (ie – change the parenting) until you have it working.