transhumandesign / kag-base

King Arthur's Gold base folder.
257 stars 119 forks source link

Arrow doesn't connect with blocks properly #1710

Open mugg91 opened 1 year ago

mugg91 commented 1 year ago

Description

When shooting at the corner of a block, the arrow will despawn instantly. If you shoot a fire arrow at the corner of a wood block, the fire arrow will despawn without igniting the block.

When shooting a fire arrow a little closer inside the wood block, it will not despawn instantly but may still not ignite the block.

Reproduction

https://i.imgur.com/7imjcFk.png - Aiming fire arrow at the corner of a wood block https://i.imgur.com/jEv0Txu.png - The fire arrow despawns

https://i.imgur.com/9n50ZYn.png - Fire arrow hits a little closer inside the block, it will not despawn https://i.imgur.com/o9eL5oo.png - But it will not ignite the block

https://i.imgur.com/IXYPiCG.png - Only if the tip of the arrow is inside the block, it will cause ignition

Played in online sandbox.

What should happen

Arrows colliding with corner of block should not instantly despawn.

Fire arrows colliding with wood blocks should ignite them more reliably.

MrPotatobird commented 1 year ago

Seems like the pos &out from map.rayCastSolidNoBlobs isn't guaranteed to map to the right tile, so the arrow thinks it's stuck in an empty block next to the one it actually hit and immediately dies because this.get_Vec2f("hitWorldPoint") is wrong. Not sure what to do about it

https://github.com/transhumandesign/kag-base/blob/34ca1e402e4d747a56bf4a88117bfce76e87f5ed/Entities/Items/Projectiles/Arrow.as#L418-L428

mugg91 commented 9 months ago

I spent hours but I cannot find a solution. Assuming the bug scenario (arrow hits the corner of a tile and despawns immediately), in the code from @MrPotatobird 's post, it will assign Vec2f end the coordinates where arrow presumably hit a solid tile, but checking for the tile in Vec2f end the tile is not solid. It's basicly like this:

dddd

rayCastSolidNoBlobs() and variants are not giving the exact coordinates of the tile that start to end pos is colliding with. This is probably worth opening a separate issue for.

You could do a custom check that checks 10 different positionings. If one of them is inside a solid tile, there is your tile coordinates.

dddd2

But this isn't optimal. You could probably do some pythagoras math but I'm not getting my head into this that much right now. My suggestion is dev should check for problems in rayCastSolidNoBlobs() and variants and possibly improve it, then we can use it to fix this arrow issue.