stujones11 / shooter

First Person Shooter Mod for Minetest
Other
30 stars 18 forks source link

Shooting straight down doesn't have any effect #37

Closed ClobberXD closed 5 years ago

ClobberXD commented 5 years ago

This is most likely because the raycast intersects the shooter themselves and next() returns the shooter's ObjectRef which is probably ignored by the code. Fixing this is just a matter of moving the raycast's initial position a little ahead of the player.

stujones11 commented 5 years ago

Fixing this is just a matter of moving the raycast's initial position a little ahead of the player.

It already is for this very reason but I will see if that maybe needs to be increased. However, if people want to 'shoot themselves in the foot' there is not much can be done to prevent that :)

stujones11 commented 5 years ago

I have increased the initial raycast offset from 1.0 to 1.5 which seems to allow shooting downwards without missing nodes/objects directly in front of the player.

This does mean that it is now actually possible to shoot yourself, so watch out for that! but I consider this to be a feature, not a bug :)

Edit: Actually, I am not sure if it is the player because although it spawns hit particles there is seemingly no damage to the player. What else is strange is that it only appears to happen with the first shot downwards after entering the game. I will look at this more closely when I have more time, it is possibly due to some weird engine bug.

ClobberXD commented 5 years ago

Both #37 and #38 have been fully fixed by their respective bugfix commits, thanks!

Will there be a 0.6.2 release?

stujones11 commented 5 years ago

Both #37 and #38 have been fully fixed by their respective bugfix commits, thanks!

I'd still like to figure out exactly what is being hit occasionally when shooting downwards. I think that this can only be player but maybe the engine prevents it from damaging itself. Have you been able to reproduce this?

Will there be a 0.6.2 release?

I would not usually make a release tag for small bug-fixes like this since both the forum and CDB downloads link directly to the master branch, however, I may do some more work on this over the weekend and maybe make another patch release then.

ClobberXD commented 5 years ago

I could try to dump the pointed_thing object to the terminal/chat, but it's most likely the shooter itself. I'll do just that, and let you know. I'm sure the engine doesn't automatically ignore self-damage - gunslinger has the issue of damaging the shooter if shooting straight down, and I'm yet to find time to fix that ;)

I may do some more work on this over the weekend and maybe make another patch release then.

Sounds good :)

ClobberXD commented 5 years ago

Tested by adding the following code within the if block at L360 in shooter/api.lua at version-0.6.1:

if pointed_thing.type == "object" then
    local obj = pointed_thing.ref
    minetest.chat_send_all("Hit an object! name: "..obj:get_player_name())
end

And I get the following output for every round fired pointing straight down:

Hit an object! name: singleplayer

The old offset was probably still making the raycast cut through the collision box of the shooter. The new offset is perfect.

That still doesn't explain why the shooter didn't take damage though... (unlike gunslinger, where the player takes damage upon shooting their own foot)

stujones11 commented 5 years ago

Ah, I think I know what the problem is https://github.com/stujones11/shooter/blob/9dacd39bbd0aa46fedacc86792a4cfd8b0d569f6/shooter/init.lua#L29 I guess there is no good reason to be doing this really, thanks for the update.

It still seems strange that it only seems to happen (for me) when I first enter the game.

ClobberXD commented 5 years ago

Oh lol. Missed that. :)

ClobberXD commented 4 years ago

In hindsight, allowing the player to shoot themselves, and instead offsetting the start of the raycast was a bad idea. This approach introduces a couple of bugs:

Self-damage doesn't make much sense, because if a player can damage themselves, they can only damage themselves (due to the origin of the ray). We added the 1.5m offset to fix this issue, but now player can't damage themselves anyway.

I think a better implementation would be to ditch the concept of self-damage (fixes bug no.2), and just skip over the shooter player when projecting a ray. This allows removing the ray origin offset, fixing bug no.1. And this is exactly what I've done - MT-CTF/shooter#1 - this commit will be added to #48 once the PR has been merged downstream.

@stujones11