2016-07-25 3 views
-1

내가 직면 한 유일한 문제는 경위에서 패트롤 속도 값을 변경할 때 캐릭터 보행의 모든 ​​속도에 영향을 미치지 않는다는 것입니다.웨이 포인트는 부드럽게 작동하지만 속도 값을 변경하면 아무런 결과가 나타나지 않습니다.

나는 창> 애니메이터에서 도보로 문자를했고, 거기에 내가 새로운 빈 상태가이 걸어 내가

이제 레이어의 기본 상태로 설정하기 위해 워크 상태를 설정 한 후 HumanoidWalk하는 모션을 설정이라고 생성 내 캐릭터는 항상 걷고 있고 스크립트로 나는 그에게 웨이 포인트 사이를 걸어 보라고 말한다.

걷는 속도를 변경하는 방법은 무엇입니까? 그것은 스크립트 내부에서 만든 변경 등의 편집기에 표시되지 않을 수있는 공공 변수 인 경우

#pragma strict 

// The list of Waypoint you want the enemy to traverse 
public var waypoint : Transform[]; 

// The walking speed between Waypoints  
public var patrolSpeed : float = 6; 

// Do you want to keep repeating the Waypoints  
public var loop : boolean = true;  

// How slowly to turn 
public var dampingLook = 4; 

// How long to pause at a Waypoint= 0;   
public var pauseDuration : float; 

private var curTime : float; 
private var currentWaypoint : int = 0; 
public var character : CharacterController; 

function Start(){ 

    //character = GetComponent(CharacterController); 
} 

function LateUpdate(){ 

    if(currentWaypoint < waypoint.length){ 
     patrol(); 
     }else{  
    if(loop){ 
     currentWaypoint=0; 
     } 
    } 
} 

function patrol(){ 

    var nextWayPoint : Vector3 = waypoint[currentWaypoint].position; 

    // Keep waypoint at character's height 
    nextWayPoint.y = transform.position.y; 

    // Get the direction we need to move to 
    // reach the next waypoint 
    var moveDirection : Vector3 = nextWayPoint - transform.position; 


    if(moveDirection.magnitude < 1.5){ 
     Debug.Log("enemy is close to nextwaypoint"); 


    // This section of code is called only whenever the enemy 
    // is very close to the new waypoint 
    // so it is called once after 4-5 seconds. 

     if (curTime == 0) 
      // Pause over the Waypoint 
      curTime = Time.time; 

      if ((Time.time - curTime) >= pauseDuration){ 
       Debug.Log("increasing waypoint"); 

       currentWaypoint++; 
       curTime = 0; 
      } 
    } 
    else 
    {  
    Debug.Log("reaching in rotation " + moveDirection.magnitude); 
     // This code gets called every time update is called 
     // while the enemy if moving from point 1 to point 2. 
     // so it gets called 100's of times in a few seconds 

     // Now we need to do two things 
     // 1) Start rotating in the desired direction 
     // 2) Start moving in the desired direction 

     // 1) Let' calculate rotation need to look at waypoint 
     // by simply comparing the desired waypoint & current transform 
     var rotation = Quaternion.LookRotation(nextWayPoint - transform.position); 

     // A slerp function allow us to slowly start rotating 
     // towards our next waypoint 
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 
       Time.deltaTime * dampingLook); 

     // 2) Now also let's start moving towards our waypoint 
     character.Move(moveDirection.normalized * patrolSpeed * Time.deltaTime); 
    } 
} 
+0

줄을 변경하려고했습니다. public var patrolSpeed ​​: float = 6; public var patrolSpeed ​​: float = 20; 하지만 같은 변화는 없다. 내가 중단 점을 사용하고 줄에 점점 않습니다 : character.Move (moveDirection.normalized * patrolSpeed ​​* Time.deltaTime); 속도는 변하지 않습니다. –

답변

0

, 에디터 내부의 순찰 속도를 설정해보십시오.

+1

일단 Animator Walk 속도를 변경하면 작동합니다. 새로운 Animator 변수가 추가되었고 Update 함수에서 Animation 변수 speed 속성을 patrolSpeed로 설정했습니다. 이제 효과가 있습니다. –