Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. namespace RootMotion.Demos {
  5.    
  6.     /// <summary>
  7.     /// User input for an AI controlled character controller.
  8.     /// </summary>
  9.     public class UserControlAI : UserControlThirdPerson {
  10.  
  11.         public Transform moveTarget;
  12.         public float stoppingDistance = 0.5f;
  13.         public float stoppingThreshold = 1.5f;
  14.  
  15.         protected override void Update () {
  16.             float moveSpeed = walkByDefault? 0.5f: 1f;
  17.  
  18.             Vector3 direction = moveTarget.position - transform.position;
  19.             direction.y = 0f;
  20.  
  21.             float sD = state.move != Vector3.zero? stoppingDistance: stoppingDistance * stoppingThreshold;
  22.  
  23.             state.move = direction.magnitude > sD? direction.normalized * moveSpeed: Vector3.zero;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement