Move cube vertices up 2 units (world) whatever cube orientation

Here’s my question

I have a cube

I rotate the cube on its x, y and z axis every frame

Finally I’d like to get the image of this cube but 2 units up the original cube. When I say image I mean that the vertices of the cube are translated to their new coordinates. (see picture)

[36223-sans+titre-1.png|36223]

How should I go about doing that… Any ideas ?

Edit Title: changed title from “3d trigonometry question” to “Move cube vertices up 2 units (world) whatever cube orientation”. Far more specific :wink:

If you want to move the cube upwards in the world space then you can translate it by using Vector3.up. Something like:

transform.position += transform.position + (Vector3.up * 2);

This will shift the cube upwards in the world ‘y’ axis by 2 units, keeping its rotation.

I finally found a solution without cube translation:

using UnityEngine;
using System.Collections;

	public class MoveVerticesUp : MonoBehaviour {
	
		Mesh mesh = null;
		Vector3[] localVerticesArray = null;
		Vector3[] globalVerticesArray = null;
	
		void Start () {

			mesh = GetComponent<MeshFilter>().mesh;
			localVerticesArray = mesh.vertices;
			globalVerticesArray = mesh.vertices;

		} // end Start
			
		void Update () {
			
			for(int i = 0; i < localVerticesArray.Length; i++)	
			{	
				globalVerticesArray _= transform.TransformPoint(localVerticesArray*);*_

globalVerticesArray_.y = globalVerticesArray*.y + 2;*_

globalVerticesArray = transform.InverseTransformPoint(globalVerticesArray*);*
* }*

* mesh.vertices = globalVerticesArray;*
* mesh.RecalculateBounds();*
* mesh.RecalculateNormals();*

* } // end Update*

* } // end class *
Works like a charm !
Thanks HarshadK for giving me tools and general flow!