rotation problem with my npc

Hello so im having this weird issue ive been researching for about the whole day now and i cant find a soulution heres what im talking about

this is the only script attached to the object or npc

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
   public Transform player;
    public float range = 50.0f;
    public float bulletImpulse = 20.0f;
    private bool onRange = false;
    public Rigidbody projectile;
    public Transform firepoint;
    public Transform target;
    void Start(){
        float rand = Random.Range (1.0f, 2.0f);
        InvokeRepeating("Shoot", 2, rand);
    }
    void Shoot(){
        if (onRange){
            Rigidbody bullet = (Rigidbody)Instantiate(projectile, firepoint.position + transform.right, transform.rotation);
            bullet.AddForce(transform.forward * bulletImpulse, ForceMode.Impulse);
        
            Destroy(bullet.gameObject, 2);
        }
    }
    void Update() {
        onRange = Vector3.Distance(transform.position, player.position)<range;

        transform.LookAt(target);
       
    }
}

thanks in advanced :slight_smile:

My first guess would be that either the target’s position and/or the enemy’s rotation aren’t what you think they are, for whatever reason.

One thing I recommend would be to set your selection widget to show the pivot point rather than the center, because the pivot point is the position it’ll actually be looking at. You can set this with the toolbar on the top on the left side, where it says “Center” - change that to pivot. Now select the object that is assigned to “target” in the inspector and see where the selection widget shows it to be - make sure that is where you expect it. (While you’re at it, double-check that “target” is pointing at the correct object, too)

Is your enemy’s transform in the correct orientation relative to the 3D model? That could cause rotations that look wrong, though I doubt it would entirely explain what’s seen in the video. With the enemy selected, the blue line (the Z axis) is pointing along what that object considers “forward” - e.g. LookAt will point that line towards the target. So does that look correct?

thanks :slight_smile: ill try and see if i can fix this tonight using what you just told me