I've never tried ambien, but I suspect that the trippy effects are due to it causing parts of your brain to function as if you were dreaming. I'm pretty sure that's how other sleeping aid-turned-recreational substances (diphenhydramine in particular) work.