c# - Can't create elevator using waypoints in Unity3d -


i have script waypoints, find here. works fine objects, move on horizontal axes. don't move objects , down. can't understand, why.

elevator decoration , randomly move 1 floor another.

public transform[] waypoint;    // amount of waypoint want  float patrolspeed = 3.0f;       // walking speed between waypoints  float dampinglook = 6.0f;       // how turn  public float pauseduration;     // how long pause @ waypoint   float curtime;  int  currentwaypoint;  charactercontroller character;   void start()  {      character = getcomponent<charactercontroller>();  }   void update()  {      if (currentwaypoint < waypoint.length)          patrol();      else          currentwaypoint = 0;  }   void patrol()  {      vector3 target = waypoint[currentwaypoint].position;      target.y = transform.position.y;    // keep waypoint @ character's height      vector3 movedirection = target - transform.position;       if(movedirection.magnitude < 0.5)      {          if (curtime == 0)              curtime = time.time;        // pause on waypoint          if ((time.time - curtime) >= pauseduration)          {              currentwaypoint = random.range(0, waypoint.length);              curtime = 0;          }      }      else      {                  var rotation = quaternion.lookrotation(target - transform.position);          transform.rotation = quaternion.slerp(transform.rotation, rotation, time.deltatime * dampinglook);          character.move(movedirection.normalized * patrolspeed * time.deltatime);      }      } 

edit1:

here video how works.

try this, without rigidbody:

using unityengine; using system.collections;  public class elevator : monobehaviour {     public transform[] waypoint;    // amount of waypoint want     float patrolspeed = 3.0f;       // walking speed between waypoints     float dampinglook = 6.0f;       // how turn     public float pauseduration;     // how long pause @ waypoint     float curtime;     int  currentwaypoint;     void update()     {         if (currentwaypoint < waypoint.length)             patrol();         else             currentwaypoint = 0;     }      void patrol()     {         vector3 target = waypoint[currentwaypoint].position;         vector3 movedirection = target - transform.position;         if(movedirection.magnitude < 0.5)         {             if (curtime == 0)                 curtime = time.time;        // pause on waypoint             if ((time.time - curtime) >= pauseduration)             {                 currentwaypoint = random.range(0, waypoint.length);                 curtime = 0;             }         }         else         {             transform.translate(movedirection.normalized * patrolspeed * time.deltatime);         }        } } 

edit: correct script removing 2 rotation lines.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -