Add terrain alignment to tortoise. Adjust patrol points
This commit is contained in:
1 parent
3cd4759b26
commit
71ca4cd8bd
6 files changed
+50
-52
No files matched your search
@@ -1,18 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TortoiseController : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
RaycastHit hit;
|
||||
Vector3 theRay;
|
||||
|
||||
public LayerMask terainMask;
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
|
||||
Align();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
private void Align()
|
||||
{
|
||||
|
||||
theRay = -transform.up;
|
||||
|
||||
if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y, transform.position.z),
|
||||
theRay, out hit, 20, terainMask))
|
||||
{
|
||||
|
||||
Quaternion targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.parent.rotation;
|
||||
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime / 0.15f);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user