Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

How to make a sprite retract to its original position?

$
0
0
I'm currently trying to implement a Yoshi's tongue, where it "whips" to a coordinate, and return back to it's original position. So far, I have gotten the tongue to leave the mouth, and travel vertically, but what could I add to it so I could achieve: 1. A max translation, (cannot moveTo further than this y-coordinate) 2. After an interval of ~0.5 seconds, the sprite retracts to it's original coordinate 3. Pushing the key down will not do anything while the tongue is at the maxTranslation, or while it is in motion So far I have this code to make the tongue go out: #pragma strict function Start () { transform.position.z = -0.5; } function Update () { if(Input.GetKeyDown ("space")) { moveTo(transform.position.y + 10, 50); // Feed the moveTo() function the X/Y positions you want to move it to, and the Speed you want to move at } transform.position.z = -0.5; } function moveTo(posY : float, speed : float) { while (transform.position.y != posY) { transform.position = Vector2.MoveTowards (transform.position, new Vector2(transform.position.x, posY), speed * Time.deltaTime); yield; } } Thanks, any help is appreciated.

Viewing all articles
Browse latest Browse all 1875

Latest Images

Trending Articles



Latest Images