2022년 6월 8일 수요일

Unity PlayerMouseLook

 



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMouseLook : MonoBehaviour
{
    public float mouseSensitivity = 1000f;

    public Transform playerBody;
   
    float xRotation = 0f;

    public GameObject checker;

    bool clicked;
    // Start is called before the first frame update
    void Start()
    {
        //Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {

        if (Input.GetKey(KeyCode.LeftAlt))
        {

            if (Input.GetMouseButtonDown(0))
            {
                clicked = true;
            }
            if (!clicked)
            {
                checker.SetActive(true);
                SetCheckerPosition();
            }

        }
        else
        {
            clicked = false;
            checker.SetActive(false);
            LookRotation();
        }




    }

    void LookRotation()
    {
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);


        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up * mouseX);
    }

    void SetCheckerPosition()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit raycastHit))
        {
            checker.transform.position = raycastHit.point;
        }
    }

   
}






Unity PlayerMovement

 




using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class PlayerMovement : MonoBehaviour
{
    public CharacterController controller;
    public NavMeshAgent playerNavMeshAgent;


    public float speed = 12f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;


    public Vector3 clickPos;

    Vector3 velocity;
    bool isGrounded;

    public bool isClicked;

   

    // Update is called once per frame
    void Update()
    {


        if (Input.GetKey(KeyCode.LeftAlt))
        {
            playerNavMeshAgent.enabled = true;
            controller.enabled = false;
            if (Input.GetMouseButtonDown(0))
            {
                MoveClickPosition();
            }
        }

        gravityMove();



        if (isClicked)
        {
           
        }
        else
        {
            NormalMove();
        }

        if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
        {
            playerNavMeshAgent.enabled = false;
            controller.enabled = true;
            isClicked = false;
        }
        //if (Input.anyKeyDown)
        //{
        //    if (isClicked)
        //        isClicked = false;
        //}
    }


    void NormalMove()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);
       
    }

    void gravityMove()
    {
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }



    void MoveClickPosition()
    {
        isClicked = true;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit raycastHit))
        {
            playerNavMeshAgent.SetDestination(raycastHit.point);
        }
    }
}





Unity UpDown Plusing

 



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpDownMove : MonoBehaviour
{

    Transform TargetObject;
    float plusSize = 0.015f;
    float tempo = 0.025f;

    private bool coroutineAllowed;
    // Start is called before the first frame update

    private void Start()
    {
        TargetObject = transform;
        coroutineAllowed = true;
    }
    // Update is called once per frame
    void Update()
    {
        if (coroutineAllowed)
        {
            StartCoroutine(StartPlusing());
        }
    }

    private IEnumerator StartPlusing()
    {
        coroutineAllowed = false;


        for (float i = 0f; i < 1f; i += 0.1f)
        {
            transform.localScale = new Vector3(
                (Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x , Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y + plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z + plusSize * 0.1f, Mathf.SmoothStep(0f, 1f, i)))

                );
            yield return new WaitForSeconds(tempo);
        }


        for (float i = 0f; i < 1f; i += 0.1f)
        {
            transform.localScale = new Vector3(
                (Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x , Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y - plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z - plusSize*0.1f, Mathf.SmoothStep(0f, 1f, i)))
                );
            yield return new WaitForSeconds(tempo);
        }

        coroutineAllowed = true;
    }
}






Unity Plusing Object(움찔움찔하는기능)

 

포인트 같은거 자동으로 움직이게 하는 코드


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Plusing : MonoBehaviour
{

    public Transform TargetObject;
    public float plusSize = 0.025f;
    private bool coroutineAllowed;
    // Start is called before the first frame update
    void Start()
    {
        TargetObject = transform;
        coroutineAllowed = true;
    }

    void OnMouseOver()
    {
        if (coroutineAllowed)
        {
            StartCoroutine(StartPlusing());
        }
    }

    private IEnumerator StartPlusing()
    {
        coroutineAllowed = false;


        for (float i = 0f; i < 1f; i += 0.1f)
        {
            transform.localScale = new Vector3(
                (Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x + plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y + plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z + plusSize, Mathf.SmoothStep(0f, 1f, i)))

                );
            yield return new WaitForSeconds(0.015f);
        }


        for (float i = 0f; i < 1f; i += 0.1f)
        {
            transform.localScale = new Vector3(
                (Mathf.Lerp(TargetObject.localScale.x, TargetObject.localScale.x - plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.y, TargetObject.localScale.y - plusSize, Mathf.SmoothStep(0f, 1f, i))),
                (Mathf.Lerp(TargetObject.localScale.z, TargetObject.localScale.z - plusSize, Mathf.SmoothStep(0f, 1f, i)))
                );
            yield return new WaitForSeconds(0.015f);
        }

        coroutineAllowed = true;
    }

}




unity move smooth

 


unity 

타겟지점까지 움직이고(smooth)

lookat을 처다보기



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class VideoClick : MonoBehaviour
{
    // Start is called before the first frame update

   
    public Camera ActiveVideoCam;

   
    public GameObject TargetPos;
    public GameObject LookAtPoint;


    PlayerMouseLook PlayLook;
    public Vector3 InitPos;

    public GameObject[] UnActiveGameObjects;


    public float moveSpeed = 1;
    private Vector3 velocity = Vector3.zero;
    IEnumerator moveCam;


    private void Start()
    {
        PlayLook = FindObjectOfType<PlayerMouseLook>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("1"))
        {
            ZoomIn();
        }

        if (Input.GetKeyDown("2"))
        {
            Out();
        }
    }


    public void ZoomIn()
    {

        foreach (var x in UnActiveGameObjects)
        {
            x.SetActive(false);
        }

        PlayLook.enabled = false;
        if (moveCam != null)
        {
            StopCoroutine(moveCam);
            moveCam = null;
        }
        moveCam = SetZoomIn();
        StartCoroutine(moveCam);

    }

    public void Out()
    {

        foreach (var x in UnActiveGameObjects)
        {
            x.SetActive(true);
        }

        PlayLook.enabled = true;
        if (moveCam != null)
        {
            StopCoroutine(moveCam);
            moveCam = null;
        }
        ActiveVideoCam.transform.position = InitPos;
    }

    IEnumerator SetZoomIn()
    {

       
        InitPos = ActiveVideoCam.transform.position;

       
       
       
        //Vector3 originPosition = ActiveVideoCam.transform.position;
        Vector3 target = TargetPos.transform.position;

        while (true)
        {
            ActiveVideoCam.transform.position = Vector3.SmoothDamp(ActiveVideoCam.transform.position, target, ref velocity, moveSpeed);
            ActiveVideoCam.transform.LookAt(LookAtPoint.transform.position);

            if (Mathf.Abs(ActiveVideoCam.transform.position.x - target.x) < 0.1f)
                break;

            yield return new WaitForEndOfFrame();
        }
       
    }

}

2022년 5월 7일 토요일

Concurrently - 두개의 프로젝트 동시에 실행시키기

일단 

Concurrently는 root 경로 터미널에서 실행

(실행시킬 폴더가 모두 포함된 경로)


루트경로에서 npm i concurrently 명령어로 concurrently 설치


생기는 json 파일에서


scripts 추가

"scripts": {
    "backend":"npm run start --prefix server",
    "frontend":"npm run start --prefix web",
    "start":"concurrently \"npm run start --prefix server\" \"npm run start --prefix web\""
  }


포인트는 --prefix인데

--prefix server

server폴더안에서 npm run start를 하라는것임


이런식으로 원하는 폴더에서 npm을 실행시킬수 있음


\" (원하는 실행경로) \" 이 문자도 꼭 지켜줘야 실행이 되는듯?


암튼 이것으로 동시에 실행 가능! npm run start만 root 터미널에서 해주면됨!

2022년 5월 4일 수요일

vue-cli-service: not found proplem on heroku?

 


heroku buildpacks:add heroku/nodejs
heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static



package.json에 scripts에 이거 추가해야함!!



"scripts": {
    "start": "npm run serve",
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
 







git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...