- Home /
Using iTween.PutOnPath
Hallo!
I'm using iTween.PutOnPath to keep my ship in a defined circle of movement.
I have two issues here that I am sure are solvable.
I want the ship's X and Y axes to be constrained to this circle, but I want it to be able to move up and down freely on the Z axis. How would I acheive this?
I understand that the position of the gamobject on the path is defined by a percentage. If I want to add / decrease percentage as the player presses the Horizontal axes, what do I do when the player is at 100% or 0%? I don't want the percentage to go negative or over 1.0 at any time.
And if you guys can think of a better way to do this, perhaps without iTween, I'd be happy to hear it ;)
Thanks! - YA
Answer by robertbu · Jul 25, 2013 at 05:28 PM
1) Create an empty game object and make the ship a child. Move the empty game object along the path. To change the 'Y', change the 'y' value of transform.localPosition of the visible ship.
2) You can use Mathf.Clamp() to clamp vaues:
percentage = Mathf.Clamp(percentage+delta, 0.0, 100.0);
3) If it really is a circle, then scripts to do this without iTween are simple. There are lots of different ways to walk the circle depending on the nature of your app. Here is one soluton. Put an empty game object at the center of your circle, place your ship on the circle and make it a child of the empty game object. Then put this script on the empty game object:
#pragma strict
var percentage = 0.0;
private var currEuler;
function Update () {
currEuler = Vector3(0.0, 360.0 * percentage, 0.0);
transform.eulerAngles = currEuler;
}
Haha that is quite a straightforward and simple solution. Thanks!
Won't the clamp keep me form, say, always going right? What if I reach 100% and want to continue moving in the + direction? Won't the clamp not allow me to do so, effectively making the player have to 'ping pong' around the circle?
Yes it will restrict the movement If you want to iTween and continue to move around the circle, then you would have to something like:
if (percentage < 0.0)
percentage = 100.0 - percentage;
if (percentage > 100.0)
percentage = percentage - 100;
All right. Thank you very much! Your help is appreciated!
Your answer
Follow this Question
Related Questions
iTween, HOTween, Spline Controller and Others 1 Answer
Dynamic animation method ✾ 1 Answer
Dog chasing my player on curved path? 2 Answers