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.
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);
}
}
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.
Yeah, I knew what you meant 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.