//Hey! you there! I, Cosmic Emerald made this script for fun and a resource, so it is fine if this is re-used, just give proper credits, k'?

addHook("PlayerThink", function(p) --main hook
	local pmo = p.mo //local variable for simplicity
	
	if not ((pmo and pmo.valid) or (pmo.skin == "s3knuckles") or (pmo.health) or (p.exiting)) //our player check
		return
	end
	
	if pmo.usetics != nil and (p.cmd.buttons & BT_CUSTOM3) and (pmo.skin == "s3knuckles") //lets set up the counter for how many tics our button is pressed
		pmo.usetics = $ + 1 //if held, the counter goes up by 1.
	else
		pmo.usetics = 0 //other wise set to 0.
	end
	
	local crouchheight = 30*FRACUNIT -- set the height for the crouch, though you can also use p.spinheight
	
	if P_IsObjectOnGround(pmo) and not (p.pflags&PF_SPINNING) -- is the player grounded?
		if (pmo.usetics ~= 0) and (pmo.skin == "s3knuckles")
		 --and (p.speed <= p.runspeed/4) //the player is pressing the specified button (our case, SPIN) and, if added back in (remove the /* */), slower than a specified speed.
			pmo.state = S_PLAY_GLIDE_LANDING -- set our animation, add sprites with the sprite subset of LAND with your character's sprites for a custom sprite.
			p.pflags = $|PF_STASIS --make sure the player can't move
			p.height = crouchheight --change the height
		else --we can use the delay from the alredy made code for the glide landing animation to a different one to our advantage!
			if (pmo.state == S_PLAY_GLIDE_LANDING) 
				p.height = 48*FRACUNIT --set our height back to normal
				if  p.pflags&PF_STASIS
					p.pflags = $ & ~PF_STASIS --allow movement
				end
			end
		end
		
		if ((pmo.state == S_PLAY_GLIDE_LANDING) and (pmo.usetics)) and (p.speed >= p.runspeed/3) --dust effects
			P_SpawnSkidDust(p, 15*FRACUNIT, sfx_s3k7e) --dust bs
		end
	end
end)