Enemy Gun pointing some where else

Hi,

I have a enemy object in my scene, which is have a gun and they will shoot the player. But the gun which is holding by a enemy is pointing some where its not pointing towards the player. I have change the transform.Lookat(“player”), then also its not changed.

I have attached the reference image below.

Thanks.

Have you checked the pivot of the gun?

You’ll probably need to rotate it to make the Z point the right way. Make sure you parent it to an empty gameobject (or enemy) to keep the local rotation so the LookAt will be using the empty gameobject’s rotation.

ya i my parent is empty object.

i have use this code to move my enemy object towards player:

transform.Translate((character.position - transform.position)* Time.deltaTime * 0.2f
transform.LookAt(character);

Does the empty gameobject look at the player correctly? If you have the Translate tool in the editor selected, the blue arrow should be pointing at the player.

If it’s looking at the player correctly, you’ll want to rotate the child weapon so it’s aligned.

now its working . But i got another issue on this. I have placed four enemy object at four sides and i have attached the one script to all the four enemies. This script is translate and Lookat script. when i run the scene all four enemy objects move to the one path and come towards, the player object.

For Example

Assume i keep one enemy object in east side and north side at the center i keep my player. When i run the scene the north side object move to hte east path and then move towards, the player.

Even if i give separate script to each enemy object it will happening.

How to solve this.?

This is the script i am using in the update for moving enemy object towards player.

timing = (int)Time.time;
		
		if(Vector3.Distance(character.position, transform.position) < 25 )
		{	
			if(timing % 4 == 0)
			{
				Emits.emit = true;
				if(Physics.Raycast(gunpoint.position, transform.forward, out hit, 50.0f ))
				{
					Player.healthpercent = Player.healthpercent - 0.01f;
				}
			}
			else
				Emits.emit = false;
		}
		
		if(Vector3.Distance(character.position, transform.position) > 5)
		{
			transform.Translate((character.position - transform.position)* Time.deltaTime * 0.2f);
			transform.LookAt(character);
		}