- Home /
Question by
Chris12345 · Jul 22, 2013 at 04:43 PM ·
itween
Itween keep speed constant
how can i make this move a object at a constant speed all the time? because right now it slows down when it reaches the next waypoint.
using UnityEngine;
using System.Collections;
public class follow : MonoBehaviour {
public bool IsleftOn = false;
public bool IsRightOn = false;
private float smoothing = 0f;
private Vector3 targetPosition;
public float runSpeed = 0;
public Transform[] path0;
public Transform[] path1;
public Transform[] path2;
private Transform[][] paths = new Transform[3][];
private int iPath = 1;
float percentsPerSecond = 0.02f; // %2 of the path moved per second
float currentPathPercent = 0.0f; //min 0, max 1
void Start () {
paths[0] = path0;
paths[1] = path1;
paths[2] = path2;
}
void Update () {
IsleftOn = PlayMakerGlobals.Instance.Variables.GetFsmBool("leftcontrol").Value;
IsRightOn = PlayMakerGlobals.Instance.Variables.GetFsmBool("rightcontrol").Value;
runSpeed = PlayMakerGlobals.Instance.Variables.GetFsmFloat("playerspeed").Value;
if (IsleftOn == true) {
if (iPath == 2) iPath = 1; else iPath = 0;
PlayMakerGlobals.Instance.Variables.GetFsmBool("leftcontrol").Value = false;
}
else if (IsRightOn == true) {
if (iPath == 0) iPath = 1; else iPath = 2;
PlayMakerGlobals.Instance.Variables.GetFsmBool("rightcontrol").Value = false;
}
currentPathPercent += percentsPerSecond * Time.deltaTime * runSpeed;
iTween.PutOnPath(gameObject, paths[iPath], currentPathPercent);
transform.LookAt(iTween.PointOnPath(paths[iPath],currentPathPercent+.03f));
}
void OnDrawGizmos(){
iTween.DrawPath(path0);
iTween.DrawPath(path1);
iTween.DrawPath(path2);
}
}
Comment
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
using itween to move objects in the 6 degrees of freedom 1 Answer
Rotating an object using itween 1 Answer
Waiting between pingpong loops 2 Answers
Parallel animation play using iTween 1 Answer