-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathSimpleNPC.cs
42 lines (34 loc) · 1.14 KB
/
SimpleNPC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEngine;
public class SimpleNPC : MonoBehaviour
{
public Transform target;
private Rigidbody rb;
public float walkSpeed = 1;
// public ForceMode walkForceMode;
private Vector3 dirToGo;
// private Vector3 m_StartingPos;
// Start is called before the first frame update
void Awake()
{
rb = GetComponent<Rigidbody>();
// m_StartingPos = transform.position;
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
dirToGo = target.position - transform.position;
dirToGo.y = 0;
rb.rotation = Quaternion.LookRotation(dirToGo);
// rb.AddForce(dirToGo.normalized * walkSpeed * Time.fixedDeltaTime, walkForceMode);
// rb.MovePosition(rb.transform.TransformDirection(Vector3.forward * walkSpeed * Time.deltaTime));
// rb.MovePosition(rb.transform.TransformVector() (Vector3.forward * walkSpeed * Time.deltaTime));
rb.MovePosition(transform.position + transform.forward * walkSpeed * Time.deltaTime);
}
public void SetRandomWalkSpeed()
{
walkSpeed = Random.Range(1f, 7f);
}
}