Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Making player face wall

Discussion in 'Scripting' started by gjfnasjdnasklnd, Jun 29, 2020.

  1. gjfnasjdnasklnd

    gjfnasjdnasklnd

    Joined:
    Jun 15, 2020
    Posts:
    8
    I have a character controller, if it touches a wall its status will become climbing. I need to transform the character so they face the wall perpendicular/head on.

    Top down view (this is a 3D project). So character walks into wall/ladder.
    upload_2020-6-29_14-16-47.png
    When OnTriggerEnter happens on character controller compound colliders, make character controller face wall.
    upload_2020-6-29_14-17-50.png

    I have a point direction Vector3 variable so I know which direction the character is facing but I don't know how to get the wall surface position(?) and how to use it on the character.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    7,612
    Various Raycast functions can optionally give you a RaycastHit object back. One of the components of that is the
    .normal
    field, which is the vector pointing away from the surface at the precise point you hit it. With that you can orient your player to face the opposite direction, i.e, into the wall.
     
    Joe-Censored likes this.
unityunity