- Home /
Block Incoming Projectiles Using Rotation (Video Included)
Hello,
I've been trying to find a way to accomplish this now for a while, but it seems like my solution isn't nearly as accurate and trustworthy as the example in the video.
As you can see in the video, the two "pods" seem to rotate around a fixed point (the middle of the player's ship) and block incoming projectiles.
I tried to replicate this by making my two pods children, and having their parent rotate itself. This way, the positions of the pods maintain the same distance away from each other and rotate in sync like in the video.
However, I am unsure how the developers of Varth managed to calculate where the pods need to rotate to. I've tried using raycasts that are drawn from the bullets closest to the player. Any ray that collides with the player lets me know that I need to begin rotating my pods. Then, I would stop rotating the pods until one of the pods collided with the raycast from the bullet.
This works only half the time though. If you look closely, you can see that the pods in the video seem to rotate back to their original position, on the side of the playership. My guess is that they do this when there aren't any projectiles that pose an immediate threat to the player.
However, when I tried to implement this behavior myself, it doesn't function as cleanly as the one in Varth does. My current solution maybe blocks the first bullet that comes my way, and sometimes blocks others if there is enough time for my pods to "reset" back to their original position. But, as you can see in the video, the pods stay in the same spot if there are multiple bullets close together in a straight line.
I am really unsure as to how they accomplished this. I don't know if their solution is very simple or complex. As of right now, I am unsure if using raycasts is the way to go. I have thought about calculating the time it will take for a certain bullet to reach my player, and determining a good position for my pods to rotate to, but I feel like this may be too expensive a calculation since there are many bullets on screen. Especially considering the fact that to get a decently accurate estimation of where a certain bullet will be at a certain point in time most likely requires a few iterations.
Also, you can see that the pods attempt to block bullets that pose greater danger, so I thought of using a priority queue, where the head is the closest bullet. However, this doesn't seem like a great solution either because both the player and enemy projectiles are constantly moving. Thus, distances are changing, meaning I would have to reconstruct the queue over and over.
I suppose I am asking what you think is the "best" way to accomplish this feature. I know that the blocking mechanic involves the bullets closest to the player, but I am not sure how they accomplished it. Thank you.