I guys, this part of code move an arm up when Z is pressed, how can I do for move at the same time the arm down always when I press Z ? So the final result should be that when I press Z the arm should go up and down continuously. Thanks! Code (CSharp): using UnityEngine; using System.Collections; public class Braccio : MonoBehaviour { public GameObject[] arm; public float SpeedUp = 0; public float acceleration = 10f; public float maxSpeed = 100f; Vector3 StartPosition; // Update is called once per frame void Update () { SpeedUp = Mathf.Clamp(SpeedUp,0f,maxSpeed); //limit maxspeeed //go up if (Input.GetKey (KeyCode.Z)) { float currentAngle = transform.rotation.eulerAngles.x; while (currentAngle < -180.0f) currentAngle += 360.0f; while (currentAngle > 180.0f) currentAngle -= 360.0f; Debug.Log ("currentAngle " + currentAngle); float destinationAngle = currentAngle - Time.deltaTime * SpeedUp; Debug.Log ("destinationAngle before clamp " + destinationAngle); destinationAngle = Mathf.Clamp (destinationAngle, -50.0f, 0.0f); Debug.Log ("destinationAngle after clamp " + destinationAngle); float deltaAngle = destinationAngle - currentAngle; transform.Rotate(Vector3.right, deltaAngle); SpeedUp += acceleration; //increase speedup } else { SpeedUp -= acceleration; //slowly stop? } } }
In my case I have transform.rotation, in the example ther's transform.position. Is the same? following the example, i made so: Code (CSharp): transform.Rotate(Vector3.right(Mathf.PingPong(Time.time, 3), deltaAngle); but unity give me error.
If you open 3 bracket , you have to close all tree too. My guess the error was: That means that the compiler does not know what to do witht he ; because he is expeting the ) before the line can end.
maybe I lost some piece when i copied the code. Anyway, my problem is not that. Hope someone can help me.. LoL
My question was how can I get the opposite movement from that script. The final result should be that if I press Z, the arm should go up and down continuously, while in that script the arm go only up. I know how make the down movement, need just put float destinationAngle = currentAngle + Time.deltaTime * SpeedDown; in another input, but this is the problem. I would like insert the down movemtent in the same input key (Z) Hope you understand me
AS in you press and then it keeps going up and down till you press again? If so you only need a bool to check whether it should be doing that or not, and then make it go up as high as you need til it reaches some condition andthen make it move down and do it all over again.