Squitz
1
Hi
When making enemy AI, i ran into an issue that made my enemy’s not render right.
(my game is still in prototype phase)
This is the code i am using
public class enemy_behavior : MonoBehaviour
{
public float speed;
public Transform playerTransform;
Rigidbody2D rigidBody;
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
rigidBody = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
Vector3 direction = playerTransform.position - transform.position;
transform.rotation = Quaternion.LookRotation(direction);
rigidBody.AddForce(transform.forward * speed);
}
}
Squitz
2
So for more detail.
The thing that it makes it stop rendering properly is this line of code in script
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
I spawn them with this line of code
GameObject Spawnedenemy = Instantiate(enemy, new Vector3(transform.position.x + Random.Range(10, 50), transform.position.y - Random.Range(10, 50), 0), Quaternion.identity) as GameObject;
And this is what it schould look like: