Title is a little confusing, but let me explain:
I want to make the enemies look at the player, and shoot at him, with random precision, meaning that one time the enemy will shoot a little bit to the left of the player, next time a little bit to the right of him, and sometimes exactly at him.
The turret rotates, and when the green direction spots the player, it shoots a bullet facing the player (the green arrow).
Now I need where the rotation is passed for the
Instantiate, to have some random precision, and I don't know how to do it. Here's what I have so far
Vector3 pos = new Vector3(firingPoint.transform.position.x, firingPoint.transform.position.y, firingPoint.transform.position.z); float playerX = playerObject.transform.position.x; float playerY = playerObject.transform.position.y; float playerZ = playerObject.transform.position.z; float randomX = Random.Range(playerX - 1f, playerX + 1f); float randomY = Random.Range(playerY - 1f, playerY + 1f); float randomZ = Random.Range(playerZ - 1f, playerZ + 1f); Quaternion aimPrecision = Quaternion.LookRotation(new Vector3(randomX, randomY , randomZ)); Instantiate(bulletPrefab, pos, aimPrecision);
How can I do this?
but never towards me, or backwards