GM:S 1.4 How to make the third person camera not to clip the walls ?

Discussion in 'Programming' started by hijong park, Feb 11, 2019.

  1. hijong park

    hijong park Member

    Joined:
    Dec 29, 2016
    Posts:
    121
    [​IMG]

    I'm making a basic Wolfenstein 3D style shooter to practice 3D. But Since I prefer Third person view over FPV for less motion sicknesses and wider view, I'm trying to make it as a third person shooter.

    Making Third person camera and Displaying my character was not hard, but there's a problem.

    When there is a wall behind the player, the camera clips through it and I can't see anything.
    How to make the camera to move closer to ther player when there's a wall behind, like many other TPS does ? I searched other 3D tutorials but couldn't find the solution about this.
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,287
    Cast a ray backwards from the player and solve for a ray-plane collision. If there is a collision, place the camera just before the collision, otherwise place it as far as the default permits. If your game is played over a 2D plane, a script like this plus lengthdir_x() and lengthdir_y() should suffice.
     
    Binsk and Bayesian like this.
  3. hijong park

    hijong park Member

    Joined:
    Dec 29, 2016
    Posts:
    121
    Thanks, It works. I didn't use the scripts you mentioned but got a hint from your comment and tried a different method.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice