54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
using System;
|
|
using SLSUtilities.General;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters
|
|
{
|
|
public class AuxiliaryDrone : MonoBehaviour
|
|
{
|
|
public Player player => MainGameManager.Player;
|
|
public GameObject droneModel;
|
|
public Transform center;
|
|
public Transform muzzle;
|
|
public Vector3 velocity, offset;
|
|
|
|
private void Update()
|
|
{
|
|
if (player.selfTimeSm.TimeScale == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Vector3 moveDirection = player.landMovementSc.horizontalMovement / player.selfTimeSm.DeltaTime;
|
|
moveDirection *= 0.1f;
|
|
|
|
Transform playerTransform = player.transform;
|
|
Vector3 cameraRight = player.viewSc.playerCamera.transform.right;
|
|
float dot = Vector3.Dot(moveDirection.normalized, cameraRight);
|
|
Vector3 realOffset = cameraRight * offset.x + playerTransform.up * offset.y;
|
|
Vector3 targetPosition = playerTransform.position + moveDirection * Mathf.Max(0, dot) + realOffset;
|
|
|
|
Vector3 dronePosition = transform.position;
|
|
float posX = Mathf.SmoothDamp(dronePosition.x, targetPosition.x, ref velocity.x, 0.1f);
|
|
float posY = Mathf.SmoothDamp(dronePosition.y, targetPosition.y, ref velocity.y, 0.3f);
|
|
float posZ = Mathf.SmoothDamp(dronePosition.z, targetPosition.z, ref velocity.z, 0.1f);
|
|
|
|
dronePosition = new Vector3(posX, posY, posZ);
|
|
transform.position = dronePosition;
|
|
|
|
/*EnemyController availableEnemy = GameManager.enemyManager.GetIdealEnemy(float.MaxValue, true);
|
|
if (availableEnemy != null)
|
|
{
|
|
Vector3 enemyPosition = availableEnemy.flexibleCenterPoint.position;
|
|
Vector3 lookAtDirection = (enemyPosition - dronePosition).normalized;
|
|
transform.forward = Vector3.Lerp(transform.forward, lookAtDirection, 0.2f);
|
|
}
|
|
else*/
|
|
{
|
|
Vector3 lookAtDirection = player.viewSc.playerCamera.transform.forward;
|
|
transform.forward = Vector3.Lerp(transform.forward, lookAtDirection, 0.2f);
|
|
}
|
|
}
|
|
}
|
|
}
|