Rotate() takes 3 parameters, x, y, z rotation as angles. Swap them around as you prefer, or change + to - if it goes inverse and so on. Having keys set like this will make keys cancel eachother out, like pressing W and S at the same time causes ring to not rotate at all. Add this script to only 1 object, any object and set ring1 and ring2 in inspector.
using UnityEngine;
using System.Collections;
public class RotateScript : MonoBehaviour {
public Transform ring1, ring2;
void Update () {
float rot1 = 0, rot2 = 0;
if (Input.GetKey(KeyCode.W)) rot1 += 10f;
if (Input.GetKey(KeyCode.S)) rot1 -= 10f;
if (Input.GetKey(KeyCode.A)) rot2 += 10f;
if (Input.GetKey(KeyCode.D)) rot2 -= 10f;
ring1.Rotate(rot1 * Time.deltaTime, 0, 0);
ring2.Rotate(0, 0, rot2 * Time.deltaTime);
}
}
You can’t, what you can do though is create an empty GameObject, make the object (ring) you have a child of it. Set the GameObject to be the value of the ring in the script. Now the GameObject is the pivot.
I hope thats clear enough, I can be quite vague at times.
I was just about to say the same, but here’s a picture. Make sure Pivot is selected in the top bar, not Center. Otherwise it depends on the 3D model on where the pivot is.
Ok thanks I can fiddle with it now to get them right
Zaflis can you please add coding to make rings rotating faster if you out holding down the keys then stat at that speed until I hit the other key then slow down and rotate the opposite way ? or it that way more complex ? It would also need a reset / return to the right way up for all and stop
Demonstrating use of FixedUpdate too, as far as i know it’s an event you don’t need deltaTime or fixedDeltaTime necessarily. Simpler for multiplication, but you don’t want to use Input’s in FixedUpdate.
Also afterthought, if you want to make the code a little shorter, you can get rid of all rot1, rot2 and rot3, and make Vector3 rot; instead.
You should really look into the tutorials in the learn section. These are all pretty easy to do with just the knowledge from 1 or 2 of those tutorials.