How can i do it to stop when i am running into a tree or something else??

i had progged a 3d Space.
Now I can walk through it, too.
But how do i tell the programm to stop when my gamefigure runs into a tree oder something else.

Please help me!!

That’s called COLLISION DETECTION and has so many solution so you should probably search the web for that, the basic idea in all of the implementations I’ve seen was checking your current position and your desired position and seeing if they are in different side of a polygon. In your case I would create a bounding box or a sphere to the object (in your case the trees) and another one for the player and check their intersection.
I hope my answer is clear to you, if you have any questions ask.