0
votes

So I've go all my objects inside a empty gameobject and I want to rotate the parent with this:

public void XRotation (Transform _xRotObj, float _xRotPower)
{
    float newRotation = _xRotObj.eulerAngles.x + _xRotPower * Time.deltaTime;
    _xRotObj.rotation = Quaternion.Euler(new Vector3(newRotation, 0.0f, 0.0f));
}

But all the objects inside the parent get rotated around there own pivot, how can I rotate the parent without the object rotating individually.

I found the RotateAround but this doesn't work either.

This is what the the object looks like(Just some loose cubes inside a emty game object)

enter image description here

This is what happens when it rotates:

enter image description here

They rotate around a wierd pivot point.

1
careful with the line float newRotation = _xRotObj.rotation.x + _xRotPower; it should probably be float newRotation = _xRotObj.eulerAngles.x + _xRotPower;maksymiuk
I changed that, but it still rotates wierdly. Ill upload some picturesanonymous-dev

1 Answers

0
votes

Aaah, found the problem! I was snapping the cubes in edit mode but I forgot that also was happening when I played the application and thats why the rotation was so wierd. I fixed it now with !Application.isPlaying:

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class CubeSnapS : MonoBehaviour {

    void Update () {
        if (!Application.isPlaying) {
            Vector3 oldPos = gameObject.transform.position;
            Vector3 newPos = new Vector3 (Mathf.Round (oldPos.x), Mathf.Round (oldPos.y), Mathf.Round (oldPos.z));
            gameObject.transform.position = newPos;
        }
    }
}