- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
NEOF · Jun 25, 2013 at 02:24 PM ·
joystickeulerangleseuler anglesmagic
Euler angles changes when I don't do this.
I'm trying to rotate ball according to joystick, and when I test my script on Ipad simulator, at some unknown point game stops changing x and z which I need, and starts rotating y, which I dont need, and then vice-versa. Here is my code: using UnityEngine; using System.Collections;
public class ControlPlayerGame : MonoBehaviour {
// Use this for initialization
public Joystick jsg;
public Joystick jsg2;
public float movespeed;
public GameObject player;// ball that I move
void Start () {
movespeed=3.0f;
}
// Update is called once per frame
void Update () {
if((jsg.position.x!=0) || (jsg.position.y!=0))
{
this.gameObject.transform.position+=new Vector3(movespeed*Time.deltaTime*jsg.position.x,0.0f,movespeed*Time.deltaTime*jsg.position.y);
Camera.mainCamera.transform.position+=new Vector3(movespeed*Time.deltaTime*jsg.position.x,0.0f,movespeed*Time.deltaTime*jsg.position.y);
player.gameObject.transform.localEulerAngles+= new Vector3(jsg.position.y*50.0f*Time.deltaTime,0.0f,-jsg.position.x*50.0f*Time.deltaTime); // I think that problem is somewhere here
}
}
}
Why is this happening? Do you have any Ideas? That is the only script that I have in program, except joystick script from standard assets(mobile).
Comment
I fixed the problem using transform.Rotate, but I still wondering why is it happening when I add value to angles.