Unbothered
Coder
Hello. I have a NPC that, detect the player when its in a certian range, however I need it to rotate towards the player and aim the bullets at the player. Right now when the player is within range it starts shooting straight but not at the player.
Here is the code for the NPC to shoot
//position of bullet
Vector3 position = new Vector3(farRangeNPC.transform.position.x, farRangeNPC.transform.position.y, farRangeNPC.transform.position.z);
var bullets = MonoBehaviour.Instantiate(prefab, position, Quaternion.identity);
The movement of the shooting is done in another script attached to the bullet prefab.
If you need more information I can definitely provide.
Here is the code for the NPC to shoot
//position of bullet
Vector3 position = new Vector3(farRangeNPC.transform.position.x, farRangeNPC.transform.position.y, farRangeNPC.transform.position.z);
var bullets = MonoBehaviour.Instantiate(prefab, position, Quaternion.identity);
The movement of the shooting is done in another script attached to the bullet prefab.
If you need more information I can definitely provide.