- Home /
How can I translate a Vector2 control system to Vector3 and rotate?
I have a very basic Vector2 virtual D-pad on my game screen that generates x/y values when pressed. However, I'd like to take the Vector2 values and translate them in order to rotate a cube in the direction pressed, but I'm not sure what to do. I'm getting the cube via Raycast. The ultimate goal is to have the cube rotate 90 degrees in the direction pressed so that a player can view all six sides of it. Can anyone offer any suggestions?
Comment
Answer by EHogger · Jul 15, 2013 at 09:10 AM
Assuming your D-pad produces either positive or negative values on each axis, you could just do something like this:
Vector2 DPadInput;
void Update(){
transform.rotate(Vector3.right * Time.deltaTime * DPadInput.y);
transform.rotate(Vector3.up * Time.deltaTime * DPadInput.x);
}
You'll probably need to change the Vector3.right and Vector3.up to rotate in the correct direction for your project though.