Place a stone foundation near Rex spawns. Then place 3 walls a door frame and a door on it. Next put 4 door frames on top of that do it should be two walls high. Then place a ceiling. Now get inside of it and shoot the Rex through the door frames on top. It won't be able to hit you. You can also tame gigas if the building is metal.

More Rex Taming & KO Tips