In the real line this problem has a nice, somewhat explicit solution: Take, for example, the standard smooth function with compact support (if there is no standard for you then just take a non-negative one with support in ), and define , now just put . Now it's standard to show that satisfies what is asked.

On the other hand, the approach you're hinted at works to construct so called "cut-off" functions over any open bounded subset, even in higher dimensions. To prove it like this, take an interval which properly contains , now let be the distance from to the complement of , the characteristic function of and take your such that its support is contained in, say, . Now it's easy to prove this functions satisfies what is asked (If you know that ).