Hi
Well, I’m sorry to bother everyone with yet another trivial question - actually there is two !
In my script have a made a cube which spin once the user click on it:
using UnityEngine;
using System.Collections;
public class RotatingCube : MonoBehaviour {
public float cubeSpeed = 50.0f;
public bool isCubeActivated = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(isCubeActivated == true){
//transform.Rotate(new Vector3(0,1,0) * cubeSpeed * Time.deltaTime);
//transform.Translate(new Vector3(0,0,1) * cubeSpeed * Time.deltaTime);
transform.Translate(new Vector3(0,0,1) * transform.Rotate(new Vector3(0,1,0) * cubeSpeed * Time.deltaTime));
}
}
void OnMouseDown (){
isCubeActivated = true; //the bool: isCubeActivated become true once the mouse pointer clicks on the cube
}
}
Then I decided that I wanted the cube to just take off along the z-axis while spinning, so I tried to combine the translation and rotation into one line of code - which ofcourse was doomed to fail as I basically don’t know WTF I’m doing !
I sense that the problem and the reason why I get errors might because I’m trying to make (instantiate) a new vector3 for the rotation, when all I basically want is the cube to translate along the vector3 while spinning.
Is my assumption correct ?
IF the answer is yes THEN how do I correct this ?
Also, please look at the two lines of code:
transform.Rotate(new Vector3(0,1,0) * cubeSpeed * Time.deltaTime);
transform.Translate(new Vector3(0,0,1) * cubeSpeed * Time.deltaTime);
When I made the first line then the cube would just rotate (as expected), but when I added the second line the cube started to go around in a huge circle - that was, for me, an utterly surprising experience and I must admit that huge laugh as I thought it was hilarious which probably has something to do with the position of camera which made the cube appear to go like 100mph. as it passed the camera.
My question in regards to the short story is: why did the cube start to go around in a circle and not just translate along the z-axis while spinning ?