RiftMayhem/Assets/Scripts/VisualEffects/BatSwarmMovement.cs
Pedro Gomes 9903af1fb7 Updates And new abilities
- Updated mirror image visuals
- New Vamp/Cultist/Satanist ability: Bat Swarm
- Updated Channeled abilities to have a cost per tick, and lowered initial costs significantly to take this into consideration.
2024-12-28 12:48:09 +00:00

84 lines
3.1 KiB
C#

using UnityEngine;
public class BatSwarmMovement : MonoBehaviour
{
[Header("Movement Settings")]
[SerializeField] private float radius = 2f; // Radius of the circular movement
[SerializeField] private float verticalAmount = 1.5f; // Amount of vertical movement
[SerializeField] private float rotationSpeed = 2f; // Base rotation speed
[SerializeField] private float bobSpeed = 1.5f; // Speed of up/down movement
[Header("Chaos Settings")]
[SerializeField] private float chaosAmount = 0.5f; // Amount of random movement
[SerializeField] private float timeVariance = 0.5f; // Variance in timing
private Vector3 startPosition;
private float individualOffset;
private float verticalOffset;
private float rotationOffset;
private void Start()
{
// Store the initial position
startPosition = transform.position;
// Generate random offsets for this specific bat
individualOffset = Random.Range(0f, 2f * Mathf.PI);
verticalOffset = Random.Range(0f, 2f * Mathf.PI);
rotationOffset = Random.Range(-0.5f, 0.5f);
}
private void Update()
{
float time = Time.time;
// Calculate base circular movement
float adjustedTime = time * rotationSpeed + individualOffset;
float x = Mathf.Cos(adjustedTime) * radius;
float z = Mathf.Sin(adjustedTime) * radius;
// Add vertical movement using a different frequency
float verticalMovement = Mathf.Sin(time * bobSpeed + verticalOffset) * verticalAmount;
// Add chaos to the movement
float chaosX = Mathf.PerlinNoise(time + individualOffset, 0f) * chaosAmount;
float chaosY = Mathf.PerlinNoise(0f, time + individualOffset) * chaosAmount;
float chaosZ = Mathf.PerlinNoise(time + verticalOffset, time + individualOffset) * chaosAmount;
// Combine all movements
Vector3 newPosition = startPosition + new Vector3(
x + chaosX,
verticalMovement + chaosY,
z + chaosZ
);
// Update position
transform.position = newPosition;
// Calculate forward direction for rotation
Vector3 direction = (newPosition - transform.position).normalized;
if (direction != Vector3.zero)
{
// Add some wobble to the rotation
float rotationWobble = Mathf.Sin(time * (bobSpeed + rotationOffset)) * 15f;
Quaternion targetRotation = Quaternion.LookRotation(direction);
targetRotation *= Quaternion.Euler(0f, 0f, rotationWobble);
// Smoothly rotate towards the direction of movement
transform.rotation = Quaternion.Slerp(
transform.rotation,
targetRotation,
Time.deltaTime * 5f
);
}
transform.LookAt(transform.parent);
}
// Optional: Visualize the movement radius in the editor
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, radius);
}
}