Last active
February 26, 2019 15:15
-
-
Save wakagomo/7dcc4c6b0214c0794892bd15847a38bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* Copyright (c) 2019 wakagomo * | |
* * | |
* This source code is released under the MIT License. * | |
* http://opensource.org/licenses/mit-license.php * | |
******************************************************************************/ | |
using UnityEngine; | |
/// <summary> | |
/// オブジェクトを中心に回転し、オブジェクトを向き続ける | |
/// </summary> | |
public class Satellite : MonoBehaviour | |
{ | |
[Tooltip("回転有無")] | |
public bool IsRotate = true; | |
[Tooltip("回転中心のオブジェクト")] | |
public Transform Target; | |
[Tooltip("回転中心からの距離"), Range(0.0f, 2000.0f)] | |
public float Distance = 5.0f; | |
[Tooltip("回転軸")] | |
public Vector3 RotateAxis = Vector3.up; | |
[Tooltip("回転速度 (rad/s)"), Range(0.0f, 3600.0f)] | |
public float RotateSpeed = 30.0f; | |
private void Update() | |
{ | |
if (!IsRotate) return; | |
Quaternion rotate = Quaternion.AngleAxis(RotateSpeed * Mathf.PI * Time.deltaTime, RotateAxis); | |
Vector3 targetPosition = Target ? Target.position : Vector3.zero; | |
transform.forward = rotate * transform.forward; | |
transform.position = targetPosition - transform.forward * Distance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment