Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Last active April 12, 2021 04:16
Show Gist options
  • Select an option

  • Save rsaenzi/f510f871a3be6a7fa94aba47d669b025 to your computer and use it in GitHub Desktop.

Select an option

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
//
// 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