Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. public class testkb : MonoBehaviour
  5. {
  6.     public NavMeshAgent agent; //object to move
  7.     public GameObject from; //origin point
  8.     public GameObject to; //point to move towards
  9.     public float kbmagnitude; //how long to move in that direction
  10.  
  11.     Vector3 kbto;
  12.     bool moving;
  13.  
  14.    
  15.     void Update()
  16.     {
  17.         if (Input.GetKeyDown("space"))
  18.         {
  19.             SetKB();
  20.         }
  21.        
  22.         if (kbmagnitude > 0)
  23.         {
  24.             agent.Move(kbto * Time.deltaTime);
  25.             kbmagnitude -= Time.deltaTime;
  26.         }
  27.     }
  28.  
  29.     void SetKB()
  30.     {
  31.         kbto = transform.position + (transform.position - from.transform.position).normalized;
  32.         kbto.y = 0.75f;
  33.        
  34.         to.transform.position = kbto;
  35.         kbmagnitude = 0.5f;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement