using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[DisallowMultipleComponent] // Only one Scripts
public class Xfactor : MonoBehaviour {
[SerializeField] Vector3 movementVector = new Vector3(5f, 5f, 5f);
[SerializeField] float period = 2f; // the full period of a circle is 2(f) secs
/* remove from inspector later
2 mods effecting float (range is awesome, gives you slider). moment 0 = no movement 1 = complete movement */
[Range(0,1)][SerializeField] float movementFactor;
Vector3 startingPos;
void Start () {
startingPos = transform.position; // the start of moving object
}
// VERY IMPORTANT FOR AI MOVEMENT!!!! Read carefully
void Update () {
float cycles = Time.time / period; //divides times the game cycle. smoothes it per frame
const float tau = Mathf.PI * 2f; // *****equals to about 6.28. look up tau for more info*****
float rawSinWave = Mathf.Sin(cycles * tau);
movementFactor = rawSinWave / 2f + .5f; // *****Crops movement and speeds or slows down obj******
Vector3 offset = movementVector * movementFactor; // displacement. multi scale vectors
transform.position = startingPos + offset; // add starting plus the offset.
}
}
I always had a problem understand this… I would just copy and paste code before without trying to understand it bc i had no one to explain it to me! lol let me know if my notes are dead on or if i miss understood something. Thank you in advance