How to rotate a (whole) Mesh procedurally?

Dear all,

I have created a mesh, in particular, an arch which is a set of many triangles (36 in number). Now i want to rotate this arch.

I have put this Mesh into a gameObject. i tried to see it as a gameObject now and that’s why i used the eulerAngles:

tmpobj = new GameObject();
tmpobj.transform.eulerAngles.y = 90;

The thing is that remains to be in the same 0 angle and doesn’t rotate. Should i follow another transform rule for my case? Do i have to use normals?

Another option is to create a new arch, setting new vertices and triangles with coordinates of Z and Y, instead of X and Y. But this option will cost me more code lines. Can avoid this?

Thank u all in advance.

Hi there,

please take another look at the docs for the eulerAngles.

Down below it says:

“Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations. When setting them to a new value set them all at once as shown above. Unity will convert the angles to and from the rotation stored in Transform.rotation.”

Try something like this

var angle = myGameObj.transform.eulerAngles;
angle.y = 90;
myGameObj.transform.eulerAngles = angle;

Hi velv,

please tell me what exacly you want to do.

Do you want it to rotate all the time in a constant motion?

(I can not add code to commets nicely, so you got a new answer)

This is one of my scripts, that rotates i.e. a space-station in one of my games (apply it to the object):

// C# Script
using UnityEngine;
using System.Collections;

public class ConstantRotationUp : MonoBehaviour {
 public float speed = 10.0f;
 void Update () {
 transform.Rotate(Vector3.up * Time.deltaTime * speed);

The script can easily be modified to be more flexible, like adding the up vector as variable. But for my simple use case here it is fixed.