Good day everybody,
I’m currently working on a simple 2d mega man like game.
I have an enemy that should reflect my bullets when I hit his front side. Now this works, but not always. Randomly the bullet gets through and hurts my enemy instead of reflecting.
As you can see, the box collider on his left is the trigger that reflects the bullet, the on on his right is the one that hurts him if it gets touched by a projectile.
The further I keep the 2 boxcolliders away from eachother, the lower the chanche that the reflect will fail. My bet is that the bullet gameobject doesn’t reflect fast enough and sometimes is able to reach that hurt box, but I have no idea how to fix that.
This code comes from my projectileController script and is attached to my projectiles/bullets.
The important part in the above code is in the if(other.tag==“Reflector”) statement.
It just turns the bullet around and sets the velocity so it will fly the other way. The ‘reflected’ boolean is so I’m able to ‘turn off’ my update function (in which the bullet gets its normal velocity), but thats not really important for my problem I think.
Anybody has come across something like this and has an idea how to fix this? Thanks.
I also have the same problem with my mario-like headjump.
My character has a box collider below his feet, so when he jumps and touches an enemy he will bounce of and kill it.
Often my character also gets hurt by touching the enemy, altough I’ve tweaked the colliders alot so that that shouldnt happen…