전기전자공학부
2018142125 조정빈
[Problem] Object의 Rotation&Translation 구현
Moon_movement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Moon_movement : MonoBehaviour
{
//공전의 중심 > Earth
public GameObject CenterObject;
//공전 속도
public float OrbitSpeed=10f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Earth를 중심으로 y축을 축으로 공전함
transform.RotateAround(CenterObject.transform.position,Vector3.up,OrbitSpeed*Time.deltaTime);
}
}
Earth_movement.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Earth_movement : MonoBehaviour
{
//rotate around의 중심 object
public GameObject CenterObject;
//공전 속도
public float OrbitSpeed = 10f;
// public float RotateSpeed = 10f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// transform.Rotate(new Vector3(0,1,0), RotateSpeed*Time.deltaTime);
//Centerobject를 중심으로 y축을 축으로 공전함
transform.RotateAround(CenterObject.transform.position, new Vector3(0,1,0),OrbitSpeed*Time.deltaTime);
}
}
Scene view

Game view






Camera_movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera_movement : MonoBehaviour
{
//카메라의 rotate 속도
public float rotatespeed = 10f;
//카메라의 translation 속도
public float translatespeed = 1f;
// public UnityEngine.Space translatespeed = 10f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//카메라의 rotate y축을 axis로 rotate
transform.Rotate(Vector3.up, rotatespeed*Time.deltaTime);
//카메라의 translate (1,0,1)방향으로 translate
transform.Translate(new Vector3(1,0,1)*translatespeed*Time.deltaTime);
}
}