ClobberXD / gunslinger

[alpha] One of the most realistic ranged weapons mod for Minetest. Consists of a gun-registration API and a comprehensive arsenal of builtin guns.
https://content.minetest.net/packages/ANAND/gunslinger
MIT License
11 stars 3 forks source link

Walking + Firing = Self Shooting #37

Open 9joshua opened 4 years ago

9joshua commented 4 years ago

If you walk forward and fire a weapon at the same time you shoot yourself. Is it possible to ignore the shooter when checking for hit objects or can the ray begin a bit further in front of the shooter?...

opt

ClobberXD commented 4 years ago

https://github.com/ClobberXD/gunslinger/blob/d20130a2db218825e419f8c3433fb5d04c83ee21/api.lua#L61-L67

The code already avoids the first pointed thing if the ray originates from within the pointed thing. Might it be possible that the ray encounters the same object again after skipping? That's highly unlikely...

Are you using the latest version (v0.24-pre) of Gunslinger?

9joshua commented 4 years ago

I cloned from the master branch 3 days ago. My version contains the code you pasted above. It only happens when walking forward so maybe due to lag from the time the check is done to when it continues to trace?

ClobberXD commented 4 years ago

From the API docs:

The map is loaded as the ray advances. If the map is modified after the Raycast is created, the changes may or may not have an effect on the object.

This means that unless the Raycast object is re-created, it shouldn't detect the same player again and again. But there is a possibility of the ray originating from outside of the shooter's collision box due to lag (is this what you were saying?), which means the code linked in the previous post will not detect the player properly. Ideally, it's better to explicitly check for the player; I wanted to avoid string comparisons as they're computationally expensive. I'll see if there's a better way to check if an object corresponds to the shooter themselves.

9joshua commented 4 years ago

Yes, I think it could be due to lag from the time the ray is initiated to when the player moves forward and the ray progresses.