Monday, 15 August 2011

unity3d - move object to another position (blinking) -


What I mean by blinking is that objects move instantly (change) into second position Gradually without showing the path of the movement? Its like popping in another position

Enter image details here

Box status, when press right, the object goes to the next position on the right and when pressed, the object goes to the next position on the left.

  speed of the public float;  

if (Input.GetKey (KeyCode.LeftArrow)) transform.Translate (new vector 3 (-Piped, 0, 0) * Time. DeltaTime);

if (input .getkey (keycode. Right arrow)) transform.Translate (new vector 3 (speed, 0, 0) * time DeltaTime );

How do I do this with my code?

If you want an instant x amount according to user input To move left and right, you can use GetKey's GetKeyDown insted to create "one step" every time the key is pressed.

But if you want to leave the pressed key and take the x amount every t using the amount of timer, when T Time has passed since the last move, then move as you say, making it "blink" something like this:

  Speed ​​of public float = 10; // X amount to move public float time = 0ff = 0.5f; / / Tim Time Private Blow Timer "Blink"; Zero start () {timer = timeToMove; // Initially you can move} Zero Update () {// Add Timer Time if (Timer & lt; timeToMove) {timer + = Time.deltaTime; } If (input.Getkey (KeyCode.A)) {// only run when the time has passed (timer> = timetavov) {conversion. Translate (new vector 3 (-pid, 0, 0) * time daltatime); Timer = 0; // Reset timer}}}  

In this case, the object runs 0.5 seconds per second, so that it snaps. You can do this for the right and you can set the pace and time as you like it.

Hope it helps.


No comments:

Post a Comment