Bullet goes sideways when the player gets hit
I have made a script so my player can shoot projectiles and also a script that makes the enemy shoot projectiles. Now everything works fine as long as the player doesn't get hit by the enemy projectiles. The player projectile shoots forward like it needs to do, the enemy shoots at the player like it needs to do, the projectiles get destroyed on collision, etc. etc. But the problem starts when the player gets hit by the enemy projectile. For some reason, when the player gets hit, the player's projectile starts shooting sideways. The more often the player gets hit, the more sideways its projectiles shoot.
I have looked at it while fullscreened on play and from the inspector and sceneview, but I can't find anything that makes the projectiles turn. The spawnpoint doesn't turn, the model doesn't turn, but for some reason the projectiles and sometimes even the raycast do.
I really hope someone can help me with this problem!
Answer by BigHandInSky · Feb 04, 2016 at 04:11 PM
From the sounds of it, somewhere you are rotating a transform - maybe not the player, but perhaps the spawn point. Now you may not be doing it, but with colliders and more specifically rigidbodies, any collision can send them flying off in an unexpected manner, which can explain how it increases per shot - every time the player is hit the rigidbody moves because of a collision.
Alternately ( Without any code showing how you're spawning this is pure guesswork ) you may be altering a variable by accident when the player is hit which affects the player projectile spawning, so it would be worth double-checking what happens when a collision is triggered/received from both the player/enemy bullet.
Hope this helps.
Thanks for the help. It seems that(since the player has a rigidbody) there is a very tiny bit of movement when the projectile hits the player. I hope I will be able to fix this soon!