Objects with triggers pass through each other
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;
}
}
Answer by sadowlight123 · Aug 05, 2017 at 04:30 PM
The solution is very simple: add to those same objects that have a trigger another collider of the same type However this time , make the second collider slightly smaller . The first big (outer) collider will be the trigger The second smaller (inner) collider will be the collider that will detect collision Hope it helps
Answer by Kingofweirdos · Aug 05, 2017 at 05:36 PM
as the other guys said you could do that or if the code is bugging out due to it not being able to find which collider is which just create a empty child and then name it trigger and put the collider on it. Done.