Last active
April 12, 2021 04:16
-
-
Save rsaenzi/f510f871a3be6a7fa94aba47d669b025 to your computer and use it in GitHub Desktop.
Script for Unity to translate a GameObject around another GameObject with constant rotation speed
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
| // | |
| // TranslationAround.cs | |
| // | |
| // Created by Rigoberto Sáenz Imbacuán (https://linkedin.com/in/rsaenzi/) | |
| // Copyright © 2021. All rights reserved. | |
| // | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class TranslationAround : MonoBehaviour { | |
| [Tooltip("Point to be used as rotation pivot")] | |
| public Transform translationPivot; | |
| [Tooltip("Rotation speed around the pivot in degrees/seconds")] | |
| public float translationSpeed; | |
| void Update() { | |
| // Rotates the game object ´translationSpeed´ degrees per second around the pivot | |
| this.transform.RotateAround(translationPivot.position, Vector3.up, translationSpeed * Time.deltaTime); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment