touch to rotaiton giving me wierd results

hey everyone, this is the snipibit from my code that im using to make the touch rotation an object, it works fine besides that it is rotating the object along the Z axis also when im telling it to rotate a value of 0, i even have a script on the object that says to keepthe rotation at 0, any help?

		if (rect.Contains(Input.mousePosition) || rect2.Contains(Input.mousePosition)  screen_cast_test_1.S_Enabled == 1  Input.GetTouch(2).phase == TouchPhase.Moved) 
	{
		
			// Get movement of the finger since last frame
	var touchDeltaPosition1:Vector2 = Input.GetTouch(2).deltaPosition;

	// Move object across XY plane
	Cam.Rotate (touchDeltaPosition1.x * speedR,touchDeltaPosition1.y * speedR,0);

Assuming the Rotate() function you’re using there is Transform.Rotate(), then note that that function applies the specified rotation in local space by default. This means (among other things) that successive rotations about the x and y axes can result in a perceived rotation about the z axis.

so is there anyway around this? 2 different scripts? 1 for x and 1 for y? i really need the ability to do both directions with this finger motion, seems weird for it to bug out into the z

It’s not weird; it’s the correct (and expected) behavior.

I’m not sure what behavior you’re after exactly, but the first thing I’d suggest is to submit Space.World as the second argument to Rotate(), and see if that gives you something closer to what you want.

jesse it looks like youve been threw this before a little with some1 else on here
http://forum.unity3d.com/threads/68932-How-to-Lock-or-Set-the-Camera%C2%B4s-Z-rotation-to-ZERO?highlight=move+camera+mouse

only thing is thats for C# and im using java

is there anyway you can help me translate it at all? it seems they somehow came with using the Z value and returning it negetive

heres an updated version of my script where i tried to implement it

	 if(Input.touchCount==3)
	 {
	 count = 1;	
	 }
	 
	 if (count == 1)
	{
		if (rect.Contains(Input.mousePosition) || rect2.Contains(Input.mousePosition)  screen_cast_test_1.S_Enabled == 1  Input.GetTouch(2).phase == TouchPhase.Moved) 
	{
		Cam.rotation.z=0;
		
			// Get movement of the finger since last frame
	var touchDeltaPosition1:Vector2 = Input.GetTouch(2).deltaPosition;
	var Az = transform.eulerAngles.z;
	var Cz = Cam.eulerAngles.z;
	
	// Move object across XY plane
	//transform.Rotate (touchDeltaPosition1.y * speedR,touchDeltaPosition1.x * speedR,0);
	Cam.Rotate (touchDeltaPosition1.y * speedR,0,-Cz);	
	transform.Rotate(0,touchDeltaPosition1.x * speedR,-Az);
	}
	}

Unlikely; Java isn’t supported in Unity.

I’m still not sure what behavior you’re after, so I don’t really know whether the code I posted in the other thread is what you’re looking for.

However, porting from C# to UnityScript should in no way be an obstacle to using the code. Converting the code should be trivial, but if you need help with it, you can always ask any specific questions you have here.

javascript / unityscript… u know what i mean lol.

basically when your fingers goes up or down, the camera rotates up and down
when your fingers goes left and right, the camera rotates left and right,

this is requiring the x and y to rotate, but z is also rotating (tilting) automatically (like u said expected)

i can get it working if i only call for 1 access to be rotating, so the touch is fine, my problem is controlling the z axis to remain 0

generally looking like a 1st person shooter, or think about citadel castle by epic.

lol… that is what im trying to do

Yeah, I knew what you meant :slight_smile: But this calling UnityScript or Unity’s JavaScript ‘Java’ thing is kind of a pet peeve. It doesn’t make any sense to me, and I don’t understand why people do it. Like I said in another thread recently, it’s like using the terms ‘C’ and ‘C#’ interchangeably just because they both start with ‘C’ (even though they’re largely unrelated languages).

Plus, referring to UnityScript as ‘Java’ does cause confusion sometimes, IMO. People do seem to get confused sometimes as to what languages Unity actually supports. Java? ‘Real’ JavaScript? Etc. And every time someone on the forums says, ‘Oh, I’m using Java’, it just adds to the confusion.

Anyway, just remember, Java and JavaScript are completely different languages, so it makes no sense to use the terms interchangeably.

I think I understand. If you want basic ‘FPS-style’ motion, then I suggest storing the orientation as two angles (pitch and yaw), updating those angles in response to user input, and then every update, rebuilding the orientation from scratch, e.g.:

transform.eulerAngles = new Vector3(pitch, yaw, 0f);

With syntax adjusted depending on the language if necessary, of course.

Found out the simplest solution… Took the orbit script from the old unity fps tutorial and changed the mouse commands to touch

Thanks for your help