Bullet Ricochet Problems

 Author: Xavier Williams


    A large problem I had this sprint was implementing bullet ricochet for an item ability. I tried multiple approaches to find a way to make the bullets bounce off walls properly before finally finding my final solution. The first thing I tried was rotating the bullet when it hit a wall. This did not work because the bullets use the projectile movement component, and with this, the rotation of the bullet does not affect the direction it moves in. Next, I tried using the built in projectile bouncing functionality of the projectile movement component.


After changing different settings, I was unable to get this to work, as the bullets would still collide with the wall without bouncing off. After this, I tried using Unreal Engine's physics system to make the bullets bounce off walls, however after trying it, I found that the physics system is not compatible with the projectile movement component that the bullets use. This resulted in bullets staying in one place without moving. After these attempts, I decided to go from trying to change the direction of the existing bullet to spawning a new bullet with a different rotation. The first problem I encountered with this approach was an infinite loop caused by the newly spawned bullet spawning in the wall the first bullet collided with, causing it to spawn another bullet. To solve this, I check to see if the bullet has any remaining bounces left. If it doesn't, it disables the collision for a small amount of time, allowing the bullet to move away from the wall.


Next, I had to decide what rotation the new bullet should have. First, I had the new bullet's rotation equal the old bullet's plus 90 degrees in  the z direction. This works for some angles, however this causes other angles to lead to the bullet rotating into the wall and moving through it. To fix this, I had to find the angle the original bullet hits the wall at, and use that to decide the new rotation. After some research, this is the solution I found.


Finally, I was able to use the z value of the newly calculated velocity vector for spawning the new bullet, keeping the original x and y values.



Comments

Popular posts from this blog

Procedural Generation - Room NavMesh Spawning

Powerups and Wall clipping