Damage knockback woes, losing tile alignment
Moderators: marionline, SDHawk
- Spoonweaver
- Liquid Metal King Slime
- Posts: 6461
- Joined: Mon Dec 08, 2008 7:07 am
- Contact:
So I noticed a glitch that happens in a very specific circumstance with the knockback scripts. If an enemy is right next to a solid wall and is facing it, and you walk into the enemy facing the same direction, you'll get launched right through the wall one tile.
(the new GIF recording feature, so damn good)
In my original scripts I made it so that the knockback direction is set to the direction of the attacker. I'm not really sure why this is happening, but thankfully there won't be a lot of instances of this happening in actual in-game scenarios.
(the new GIF recording feature, so damn good)
In my original scripts I made it so that the knockback direction is set to the direction of the attacker. I'm not really sure why this is happening, but thankfully there won't be a lot of instances of this happening in actual in-game scenarios.
Hmm, I took special care to make sure you get knocked back to the left in that case. Maybe you forgot to remove the "player hurtdir := npc direction(ref)" line from "damage player"?
However, that doesn't explain why knockback is pushing the player through a wall. That's pretty concerning.
Ah... I think I can guess why that's happening. The script only checks that the knockback doesn't push an NPC/player through a wall, but allows normal npc/hero movement to continue. The builtin movement only does collision checking at the beginning of every step. So I need to make it check whether the hero/npc is walking, and if so, if it's about to walk through a wall.
However, that doesn't explain why knockback is pushing the player through a wall. That's pretty concerning.
Ah... I think I can guess why that's happening. The script only checks that the knockback doesn't push an NPC/player through a wall, but allows normal npc/hero movement to continue. The builtin movement only does collision checking at the beginning of every step. So I need to make it check whether the hero/npc is walking, and if so, if it's about to walk through a wall.
Last edited by TMC on Sun Jan 29, 2017 8:23 am, edited 1 time in total.
Oh god, whoops. I totally overlooked that script block with calculate player hurtdir. I just implemented it and it works well, better than before because going through an enemy when you run into them and they're facing away from you was a little wonky anyways.
Thanks again TMC, this is ridiculously awesome.
Thanks again TMC, this is ridiculously awesome.
Alright, self-necroing this thread.
Thanks to Morpheus Kitami I've found out how the whole getting knocked into walls thing is happening, here's a GIF I recorded with infinite health:
As you can see, there are 3 instances where a ridiculously fast knockback 'jump' is occurring. The third one is what knocks the hero into the tree, and the automatic game over feature occurs shortly thereafter.
I'm guessing that the knockback is getting multiplied somehow when the hero is inside of the NPC's space. Here's the script I'm using for player knockback, the first is the "inflict damage" one and the second is the one that gets checked every frame.
Now, the only thing I changed with TMC's original scripts was adding the separate "calculate player hurtdir" scripts, so that I could use the slice X/Y of a projectile - which is just a slice, it isn't an NPC nor does it have a NPC parent - to calculate knockback. It just replaces "npc pixel x/y" with "slice x/y", that's the only difference.
Thanks to Morpheus Kitami I've found out how the whole getting knocked into walls thing is happening, here's a GIF I recorded with infinite health:
As you can see, there are 3 instances where a ridiculously fast knockback 'jump' is occurring. The third one is what knocks the hero into the tree, and the automatic game over feature occurs shortly thereafter.
I'm guessing that the knockback is getting multiplied somehow when the hero is inside of the NPC's space. Here's the script I'm using for player knockback, the first is the "inflict damage" one and the second is the one that gets checked every frame.
Code: Select all
script, damage player, damage, ref, begin
play sound (2)
suspend player
if (get npc id (ref) >= 0) then (calculate player hurtdir npc(ref)) #Checks that the "ref" arg is an NPC
elseif (slice is valid(ref)) then (calculate player hurtdir slice(ref)) #...or if it's a slice
if (damage >= 2 && check tag (tag:have best armor)) then (player health := player health -- damage +1)
else (player health := player health -- damage)
update player health
if (player health > 0) then (
player hurtframe := 8
player iframes := 30
)
end
Code: Select all
if (player hurtframe > 0) then (
switch (player hurtdir) do (
case (north) knockback player (north, 0, -5)
case (east) knockback player (east, 5, 0)
case (south) knockback player (south, 0, 5)
case (west) knockback player (west, -5, 0)
)
decrement (player hurtframe)
if (player hurtframe <= 0) then (
resume player
)
)
The large knockback happens when the player's 20px forward movement is added to the 20px knockback when they're in the same direction. Ignoring the wall-checking problem, are you saying that isn't desirable? The only alternative I can see is not doing knockback in that case. I guess that also potentially could avoid the wall checking problem without actually having to fix it.
Oh, my point was that the huge jumps are the obvious cause of the player getting shoved into walls, so it should be fixed. The normal knockback behavior is just fine. I don't know if there's any way to fix it or not though, the scripts you wrote to make it work didn't make any sense to me but they did work so I went ahead and just implemented them.
Getting rid of knockback this late into development would kind of suck, especially if it can be fixed somehow.
Getting rid of knockback this late into development would kind of suck, especially if it can be fixed somehow.
(Oh, I was wrong, the knockback is 40 pixels, not 20)
I tried doing the same thing as you, giving myself infinite hp and running back and forth on top of monsters. I found that it takes a while for the bug to appear, it's quite rare. Thank goodness for --recordinput! By recording and replaying input I can be sure I fixed the problem (or at least the bug I saw).
BTW, you don't need to separate 'calculate player hurtdir' scripts, just pass the npc slice to the slice-based one.
I would also write "player health -= damage -- 1"
The fixed scripts. Pretty dang verbose: https://hastebin.com/zaloqoruja.hss
I tried doing the same thing as you, giving myself infinite hp and running back and forth on top of monsters. I found that it takes a while for the bug to appear, it's quite rare. Thank goodness for --recordinput! By recording and replaying input I can be sure I fixed the problem (or at least the bug I saw).
BTW, you don't need to separate 'calculate player hurtdir' scripts, just pass the npc slice to the slice-based one.
I would also write "player health -= damage -- 1"
The fixed scripts. Pretty dang verbose: https://hastebin.com/zaloqoruja.hss
Last edited by TMC on Sun Mar 19, 2017 4:51 am, edited 3 times in total.
Woohoo! I enabled infinite health and ran into the purple ghosty monsters for a good 5 minutes straight and nothing bad happened. I do believe you've fixed it.
Also improved my damage player script, per your suggestion:
Can't thank you enough for helping with this part of the game coding, I had no idea it would be this troublesome when I first started the project.
Also improved my damage player script, per your suggestion:
Code: Select all
script, damage player, damage, sl, begin
play sound (2)
suspend player
calculate player hurtdir (sl)
##Armor reduces damage by 1 if greater than 1 damage is being dealt
if (damage >= 2 && check tag (tag:have best armor)) then (decrement (damage))
player health -= damage
update player health
if (player health > 0) then (
player hurtframe := 8
player iframes := 30
)
end
Last edited by Foxley on Sun Mar 19, 2017 5:09 pm, edited 1 time in total.