Hello, I have a bit of a problem. See, in this game I’m making, I have a cube which will try and attack the player cube. When the enemy cube manages to get to the player cube, it will deal damage. Both of them have box colliders and rigidbodies. The problem is, when I set the enemy cube to be a trigger, the enemy cube just passes into the enemy. I want the cube to still collide with the player, not pass into the player, and I don’t know how to fix this issue. Would someone mind giving me some advice on this issue? Thanks!
Here’s the script that controls the enemy cube, in case you need it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyController : MonoBehaviour {
public Transform targetPlayer;
public Transform myEnemy;
public int moveSpeed = 3;
public int rotationSpeed = 3;
public int damagePoints;
void Awake()
{
myEnemy = transform;
}
void Start()
{
targetPlayer = GameObject.FindWithTag("Player").transform;
}
void Update()
{
var lookDir = targetPlayer.position - transform.position;
lookDir.y = 0;
myEnemy.rotation = Quaternion.Slerp(myEnemy.rotation, Quaternion.LookRotation(lookDir), rotationSpeed*Time.deltaTime);
myEnemy.position += myEnemy.forward * moveSpeed * Time.deltaTime;
}
}