Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.AI;
- public class testkb : MonoBehaviour
- {
- public NavMeshAgent agent; //object to move
- public GameObject from; //origin point
- public GameObject to; //point to move towards
- public float kbmagnitude; //how long to move in that direction
- Vector3 kbto;
- bool moving;
- void Update()
- {
- if (Input.GetKeyDown("space"))
- {
- SetKB();
- }
- if (kbmagnitude > 0)
- {
- agent.Move(kbto * Time.deltaTime);
- kbmagnitude -= Time.deltaTime;
- }
- }
- void SetKB()
- {
- kbto = transform.position + (transform.position - from.transform.position).normalized;
- kbto.y = 0.75f;
- to.transform.position = kbto;
- kbmagnitude = 0.5f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement