CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2011
    Posts
    0

    Exclamation How to walk on terrain and not go through walls ?

    Hi, please help me implement simple character controller based on basic physics. I read hundreds of tutorials and articles, but didn't find answer, explanation with short code. I can't handle two "basic" things in moving around 3D world:

    1.) How can I make my character (it can be a first person camera, a cube or any other mesh) doesn't go through walls ? I'm moving forward in my 3D world -> there is a wall or any other object (chest, car, building) in front of me -> so I can't go, I have to stop! How to do this ???

    2.) How can I make my character goes on terrain that is not flat, but has slopes ? My object must be stuck to a ground. I'm moving forward and if a terrain rises, so my object also moves up (Y axis). I'm walking -> there is no ground/floor under my legs -> I'm falling down (Y axis) as long as there is some kind of object (terrain, floor, any other plane) under my legs. How to do this ???

    How is it done in real 3D games ?

    Please help!

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: How to walk on terrain and not go through walls ?

    Detecting collisions is time consuming, but it is not very difficult.

    You simply look if there is a wall in front of you and look at the altitude of the ground below your feet. You might also look if there is another character in your way.

    How do you "look" at things?
    If you have a map with every obstacle, then this is quite easy.
    Otherwise, you need to use sensors to feel if there are obstacles or not.
    If you have one camera, you cannot know the distance from a wall unless the wall has some painted patterns whose size you already know.
    If you have two cameras, you can compute the distance with the parallaxe and a visual reference on the wall.
    Or you can have an arm with a piston and a string. If the piston touches something, then the string is compressed, and the length of the arm is shortened. You can detect the length of the arm with diodes or piezoelectric sensors.

  3. #3
    Join Date
    May 2005
    Location
    Estonia
    Posts
    235

    Re: How to walk on terrain and not go through walls ?

    Watch this guy channel, he got a lot of good vids, including 3D collision and basic FPS game.

    http://www.youtube.com/user/thecplusplusguy

    Tuts:
    http://www.youtube.com/watch?v=W2QrXv2yZhE
    http://www.youtube.com/watch?v=s5m391a5HFg
    http://www.youtube.com/watch?v=jEm_Vq6Ply8


    Here is the game:
    http://www.youtube.com/watch?v=gbdEe1itvEA

    He will soon upload video tutorial about the game.
    He just too busy atm in university.
    Rate my post if i it was useful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured