it's true that the func apply_gravity() is putting motion.y to 0 when is_on_floor
if the code from Slsilicon28 is not what you are looking for (i think he wants the player to jump when it hits the spikes)
maybe try
func apply_gravity() #remove the is on floor and stuff
motion.y += gravity (you can use delta but then you need to place it as a parameter in your function)
and in
func _physics_process()
motion = Move_And_Slide(motion, Up) #instead of move_and_slide(motion, Up)
and if u use the += instead of = for motion.x you need to set a max speed or your player wil run very fast :)
i like to use lerp for that, i think in godotscript its like this (not sure)
motion.x = lerp(motion.x, maxspeed, 0.5)
i use C# so for me it's
motion.x = Mathf.lerp(motion.x, maxspeed, 0.5f);
hope this will help