Simulate bullets depending on various factors

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 23OO23

Hello

I am a beginner at Godot and programming overall, but, for various reasons I’ve decided to create a game on my own. That said I will appreciate any tips without hassling anyone for specifics, I can research things on my own. But I have no idea how to even begin to tackle this specific problem.

I want to create a top down shooter cRPG where stats matter amongst others for hit chance. Now, I want to make hits take place where I aim while taking into account various things, such as distance, obstacles, enemy stats, weapon stats, etc. Alas, I have no idea how to exactly make these “hits” to appear in a reticle, with whole mechanic being also used by enemies.

My only idea right now, is that it would work like a normal shooter - bullets fly normally, but the ones that are “successful” ignore everything and hit a spot in the aiming reticle (to put it into perspective, shooting beneath someone’s legs behind them, so even though the bullet flew at that someone, the shot was aimed behind, so it did not hit them). Whether or not the success would occur, would be taken from stats - I believe once I learn how to make this way of shooting, I should be able to figure the rest out on my own. But right now, I have no idea how to begin.

Thank you for any and all tips.

:bust_in_silhouette: Reply From: leo-pnt

Ray-casting is the most efficient way (afaik) of handling shoot/hit events. Now if you want to add physics (gravity to the bullet, collision detection, etc…) you can use Rigidbodies where your reticle can be an Area. I believe you are in 3D here but the principles are the same in 2D

Sometimes, I use a Raycast and add animations to fake the physics. Just a lot simpler

Thank you for the answer.

Considering I would simply use Ray-cast, what would be the best approach to make it get data on a specific path to the cursor/aiming reticle? Should I combine both ray-cast and spread to form a fan so to speak and have any missing shots hit randomly wherever the raycast ends?

Since currently I am unsure how to make shots end at the reticle as long as the ray-cast can go there (assuming for example it ends at obstacles like walls, trees, etc.). I’ve found a tutorial on having hits on the end of the raycast, but in that case it looks for a hitbox. And I’d like it to end at the cursor.

23OO23 | 2021-03-14 23:26