deltavr multiplayer 2.0
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
public class NavPointFollower : MonoBehaviour
|
||||
{
|
||||
public NavPoint startNavPoint;
|
||||
public float rotationSpeed = 1f;
|
||||
public float speed = 1f;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
var transform1 = transform;
|
||||
var position = transform1.position;
|
||||
_rigidbody.MovePosition(position + transform1.forward * (speed * Time.deltaTime));
|
||||
|
||||
var direction = (startNavPoint.transform.position - position).normalized;
|
||||
|
||||
direction.y = 0;
|
||||
|
||||
var lookRotation = Quaternion.LookRotation(direction);
|
||||
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
|
||||
|
||||
|
||||
if (Vector3.Distance(transform.position, startNavPoint.transform.position) < 0.3f)
|
||||
{
|
||||
startNavPoint = startNavPoint.GetNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user