Search Unity

3rd Person Camera

Discussion in 'General Discussion' started by suIly, Aug 1, 2019.

  1. suIly

    suIly

    Joined:
    Jun 21, 2017
    Posts:
    16
    I've been working on this for about a day or two, but I finally figured it out!

    It's pretty simple...
    Code (CSharp):
    1. transform.position = followObject.position + offset;
    2.  
    3.  
    4.         transform.LookAt(lookObject);
    5.         Vector3 finishedRotation = new Vector3(lookObject.eulerAngles.x, transform.eulerAngles.y, lookObject.eulerAngles.z);
    6.  
    7.         if(Physics.Linecast(raycastPoint.position, transform.position, out hit))
    8.         {
    9.             transform.position = hit.point;
    10.             print("collided with wall");
    11.         }
    The raycastpoint.position should be a transform near the player, but not touching it. If it doesn't work, that's because the transform is in the player, and the linecast is touching it, so move it out.



    I don't want credit, I was just showing this off.
    If you have any questions, just reply!
     
    Ony likes this.