1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    void Update()
    {
        if (middle)
        {
            targetPosition = target.GetChild(0).position;
            targetRotation = target.GetChild(0).rotation;
        }
        else if (last)
        {
            targetPosition = target.GetChild(1).position;
            targetRotation = target.GetChild(1).rotation;
        }
        print(lookDirection);
        transform.localPosition = Vector3.Lerp(transform.position, targetPosition, nSpeed * Time.deltaTime);
        transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, nSpeed / 4f * Time.deltaTime);
    }
cs

칙칙폭폭 기차놀이입니다.. 어제의 도움으로 이어 붙이고 그냥 움직이는데까지는 만들었는데 생각해보니 기차가 코너를 돌 때 회전을 해야겠더라고요. 

지금 상태로 하면 회전도 잘 되는데 position이 앞 기차의 끝부분이라 다음 기차의 중간부분이 앞 부분의 끝을 중심으로 이동해서 겹쳐져요.

그래서 기차 사이에 간격을 주려고 

            targetPosition = target.GetChild(0).position + (Vector3.forward * (renderer.bounds.size.z + zOffset)) / 2;

으로 수정을 해보니까 기차가 간격은 제대로 유지하는데 z축에서 좀만 벗어나도 막 이탈한 것 처럼 / / / 이런 모양으로 회전해영 당근빠따 Vector3.forward를 써서 그렇겠죠
       targetPosition = target.GetChild(0).position;
걍 이렇게 하면 회전은 잘 되는데 기차에 간격이 안 생기는데 어떻게하면 좋을까여
간격은 (renderer.bounds.size.z + zOffset)) / 2 이정도를 줄려고 해여

1줄 요약 : 기차 사이에 간격을 주고 회전도 이어져서 회전하게 만들고 싶다

viewimage.php?id=2abcdd23dad63db0&no=29bcc427b38a77a16fb3dab004c86b6fefd5355bb21004331c884566e8f3c822af7c0ca993a0244ff0c592c945d74b9839c103d1a6c33dbc12 프리팹은 이런 상태임. forward는 차량의 앞부분, back은 차량의 뒷부분에 위치함