UnityFactory_#05

Rioยท2021๋…„ 8์›” 26์ผ
0

Unity

๋ชฉ๋ก ๋ณด๊ธฐ
5/6

๐Ÿ‘€ 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);
            }
        }
    }
}
profile
์šฐ๋‹นํƒ•ํƒ• ๊ฐœ๋ฐœ ๊ธฐ๋ก์ง€

0๊ฐœ์˜ ๋Œ“๊ธ€