When projectile collides with enemy, enemy flies backwards. Disable this?

Hello,

I’ve searched google and the unity boards and haven’t found what I’m looking for. So far I’ve tried:
-Changed kinematic values on collision enter/exit
-Destroyed projectile on collision

Basically, the player shoots a projectile into an enemy. I just want the enemy to take damage. I don’t want the enemy to have any physical movement or reaction to the collision.

On the projectile I have:

function OnCollisionEnter (other: Collision) {
if (other.gameObject.tag==“Enemy”){
Destroy(gameObject);
}
}

On the enemy I have:

var Health = 10;

function OnCollisionEnter (other: Collision) {
if (other.gameObject.tag==“Brainwave”){
Health–;
}
}

The health is working fine. I just need the enemy to stop getting knocked back on collision. Any advice?

(Please ignore the lack of tabbing… The forum seems to line it all up when I post).

One method is to just disable the collision affect between both objects in Edit → Project Settings → Physics, then uncheck the 2 corresponding layers.

You have to assign the objects into the corresponding layers first.

After that, just use the OnCollisionEnter to trigger effects.

Edit: I was just thinking, in theory, with collision between the 2 objects disabled, it might not detect collision. If that’s the case, you may have to add another step, to parent a box collider set to Trigger, and use OnTriggerEnter.

Hi,

you could toggle IsTrigger in the collider of the projectile to on and check OnTriggerEnter instead.

Is your bullet a Rigidbody? Try reducing its mass.

Yeah that will stop all collisions between the layers… which is exactly what the OP doesnt want to do.

Setting the mass to nothing is a better option. Make sure your enemy has Mass though.

Worked like a charm. I set the projectile’s mass to .0000001. Thank you!