So, in my game, the Powerup (capsule) has a RigidBody and a Box Collider. I’ve set the Box Collider to «is trigger». When the player hits the powerup, it disappears - just as it’s supposed to.
Is it possible to let the enemies collide with the powerup (bump into it) instead of just passing through it? From the Enemy script:
void Start()
{
enemyRb = GetComponent<Rigidbody>();
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
if (player != null && gameManager.isGameActive)
{
enemyRb.AddForce((player.transform.position - transform.position).normalized * speed);
}
if (transform.position.y < -4)
{
Destroy(gameObject);
gameManager.UpdateScore(pointValue);
}
}
From the PlayerController script:
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Powerup"))
{
hasPowerup = true;
Destroy(other.gameObject);
}
}