//Special thanks to ClaireBun.

addHook("PlayerThink", function(player)
    for player in players.iterate
	   if player.mo and player.mo.skin == "fang" and player.playerstate == PST_LIVE
end

local tmom = FixedDiv(FixedHypot(player.rmomx,player.rmomy),player.mo.scale)
local speedup = (player.powers[pw_sneakers]) or (player.powers[pw_super])
local momangle = R_PointToAngle2(0,0,player.rmomx,player.rmomy)
local mom = FixedHypot(player.mo.momx,player.mo.momy)

  if player.charability == CA_BOUNCE then
		//Create bounce history
		if player.bouncelast == nil then
			player.bouncelast = false
		end
				
	if player.pflags&PF_BOUNCING and not(player.bouncelast)
   	 or (not(player.pflags&PF_BOUNCING) and player.pflags&PF_THOKKED and player.bouncelast)
			player.mo.momx = FixedMul(P_ReturnThrustX(nil,momangle,tmom),player.mo.scale)
			player.mo.momy = FixedMul(P_ReturnThrustY(nil,momangle,tmom),player.mo.scale)
			player.mo.momz = $*2
		end
		  //Update bounce history
			player.bouncelast = (player.pflags&PF_BOUNCING > 0)
		end
	
	if (player.mo.eflags & MFE_JUSTHITFLOOR) and player.mo.state == S_PLAY_BOUNCE_LANDING
	    P_SetObjectMomZ(player.mo, 20*FRACUNIT)
		player.mo.state = S_PLAY_BOUNCE
	   end
    end						
end)
