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

public class CSightVisualizer : MonoBehaviour
{
    public float radius = 3;


    private void OnDrawGizmos()
    {
        GizmosExtensions.DrawWireArc(this.transform.position, this.transform.forward, 360, radius);
    }
}

 

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

public class Capsule : MonoBehaviour
{
    public float speed = 5f;
    void Start()
    {
        
    }

    void Update()
    {
        Move();
    }

    private void Move()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        Vector3 movement = new Vector3(h, 0, v);
        this.transform.Translate(movement * speed * Time.deltaTime);
        
    }
}

 

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

public class Sphere : MonoBehaviour
{
    public float radius = 3f; // 원의 반지름
    public float rotationSpeed = 30f; // 캡슐의 회전 속도 (각도/초)

    private Transform capsuleTransform; // 부모 오브젝트인 캡슐의 Transform

    private void Start()
    {
        // 부모 오브젝트인 캡슐의 Transform 가져오기
        capsuleTransform = transform.parent;
    }

    private void Update()
    {
        if (capsuleTransform != null)
        {
            // 현재 시간에 따른 회전 각도 계산
            float rotationAngle = Time.time * rotationSpeed;

            // 원 주위를 도는 위치 계산
            float x = Mathf.Cos(rotationAngle) * radius;
            float z = Mathf.Sin(rotationAngle) * radius;

            // 부모 오브젝트의 위치를 기준으로 위치 설정
            transform.position = capsuleTransform.position + new Vector3(x, 0f, z);
        }
    }
}

 

Quaternion.

https://docs.unity3d.com/kr/2020.3/Manual/class-Quaternion.html

 

중요 클래스 - Quaternion - Unity 매뉴얼

Unity는 Quaternion 클래스를 사용하여 게임 오브젝트의 3차원 방향을 저장하고, 이를 통해 한 방향에서 다른 방향으로의 상대 회전을 설명합니다.

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/Quaternion.html

 

Unity - Scripting API: Quaternion

They are compact, don't suffer from gimbal lock and can easily be interpolated. Unity internally uses Quaternions to represent all rotations. They are based on complex numbers and are not easy to understand intuitively. You almost never access or modify in

docs.unity3d.com

using UnityEngine;

public class Sphere : MonoBehaviour
{
    public float radius = 3f; // 원의 반지름
    public float rotationSpeed = 30f; // 캡슐의 회전 속도 (각도/초)

    private Transform capsuleTransform; // 부모 오브젝트인 캡슐의 Transform

    private void Start()
    {
        // 부모 오브젝트인 캡슐의 Transform 가져오기
        capsuleTransform = transform.parent;
    }

    private void Update()
    {
        if (capsuleTransform != null)
        {
            // 캡슐의 회전 각도 계산
            float rotationAngle = Time.time * rotationSpeed;

            // 쿼터니언으로 캡슐의 회전을 설정
            Quaternion rotation = Quaternion.Euler(0f, rotationAngle, 0f);

            // 캡슐의 회전을 기반으로 원 주위를 도는 위치 계산
            Vector3 positionOffset = rotation * (Vector3.forward * radius);

            // 부모 오브젝트의 위치를 기준으로 위치 설정
            transform.position = capsuleTransform.position + positionOffset;
        }
    }
}

'산대특 > 게임 클라이언트 프로그래밍' 카테고리의 다른 글

Tank - Rigidbody.MovePosition  (0) 2024.03.06
UniRun  (4) 2024.03.05
Dodge game  (0) 2024.03.04
코루틴 연습  (0) 2024.03.03
StarCraft - Tank  (0) 2024.02.29

+ Recent posts