Skip to content

Instantly share code, notes, and snippets.

@pppoe252110
Created October 2, 2023 12:29
Show Gist options
  • Save pppoe252110/923e60d995ad904034e1540fc5dafb43 to your computer and use it in GitHub Desktop.
Save pppoe252110/923e60d995ad904034e1540fc5dafb43 to your computer and use it in GitHub Desktop.
Move Object In Square Shape Formula
using UnityEngine;
public class MoveInSquareShape: MonoBehaviour
{
public float size = 1f;
public float rotation = 0f;
private void Update()
{
transform.localPosition = Quaternion.Euler(0, 0, rotation) *
Vector3.up * size / Mathf.Cos(Mathf.PingPong(rotation, 45f) * Mathf.Deg2Rad) / 2f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment