refactor ray cast, add basic collision detection