The first thing that jumps out at me is that you set the variables by, bx, and bz and then change them into something else. Try out:
var posdy = by
var posdx = bx
var posdz = bz
that makes more sense to me. I deal mainly with 2D and I'm not sure what the context of your code is so I hope that helps.