UnityFactory_#05

👀 Vector3.Learp()

 void Move() 
    {
        Vector3 dir = target.transform.position - gameObject.transform.position ;
        dir.Normalize();
        //transform.position += dir * speed * Time.deltaTime
        //cc.Move(dir * speed * Time.deltaTime);    
        cc.SimpleMove(dir * speed); //점프 못함
        //target을 바라보게 하고 싶다
        //1. transform.LookAt(target.transform);
        //2. transform.forward = dir;
        //+ 부드럽게 회전하고 싶다
        transform.forward = Vector3.Lerp(transform.forward, dir, rotSpeed * Time.deltaTime);

    }

FSM 상태머신

두 물체간 거리 구하기

  1. Vector3.Distance(물체1위치, 물체2위치)
  2. 벡터로 구하기
    Vector3 dir = target.transform.position - gameObject.transform.position ;
    float distance = dir.magnitude;

원충돌

Vertex, Edge, Polygon, Mesh

Vertext : 점, Edge : 선, Polygon : 면, Mesh : 면의 모음
Material
-> texture
-> shader: mesh를 어떤 느낌으로 그릴지 정의한 것

CharacterController 움직임구현

public class PlayerMove : MonoBehaviour
{
    public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;
    void Update()
    {
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded)
        {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            speed = 6.0F;
            if (Input.GetKey(KeyCode.LeftShift)) //달리기 구현
            {
                speed = 12.0F;
            }
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;
        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    } 
}

1인칭 시점 만들기

  • 마우스에 따라 시점 회전하기


public class PlayerRot_00 : MonoBehaviour
{
    //마우스의 회전 누적치를 저장할 변수
    float mx;
    float my;

    //회전할 속도
    float rotSpeed = 500;

    //회전 가능 여부
    public bool canRotH;
    public bool canRotV;

    // 진동 크기
    public float amp = 0.07f;
    public float freq = 20;
    float tempY;

    private void Start()
    {
        tempY = transform.localPosition.y;
        mx = transform.localEulerAngles.x;
        my = transform.localEulerAngles.y;
    }

    void Update()
    {
        //마우스의 움직임을 받아서
        float h = Input.GetAxis("Mouse X");
        float v = Input.GetAxis("Mouse Y");

        //마우스의 회전값으로 각도를 누적하고(계산하고)
        if (canRotV)
            mx += v * rotSpeed * Time.deltaTime;
        if (canRotH)
            my += h * rotSpeed * Time.deltaTime;

        //mx 최소값을 -60, 최대값을 60으로 셋팅
        mx = Mathf.Clamp(mx, -60, 60);
        //누적된 회전값으로 게임오브젝트의 각도를 셋팅하자
        transform.localEulerAngles = new Vector3(-mx, my, 0);

        // 만약 카메라라면 
        if (gameObject.tag == "MainCamera")
        {
            if (Input.GetButton("Horizontal") || Input.GetButton("Vertical"))
            {
                amp = 0.07f;
                freq = 20;
                if (Input.GetKey(KeyCode.LeftShift)) //달리기 구현
                {
                    print("shift눌림");
                    amp = 0.07f;
                    freq = 50;
                }
                transform.localPosition = new Vector3(0, tempY + amp * Mathf.Sin(freq * Time.time), 0);
            }
        }
    }
}

좋은 웹페이지 즐겨찾기