Oscillation movement code

[DisallowMultipleComponent]
public class Oscilation : MonoBehaviour
{
    [SerializeField] Vector3 movementVector;

    [Range(0, 10)] float movementpercentage;

    Vector3 startingPos;
    // Start is called before the first frame update
    void Start()
    {
        startingPos = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        float sinwave = Mathf.Sin(Mathf.PI * Time.time);
        movementpercentage = sinwave / 2f;
        
  
 
        Vector3 offset = movementVector * movementpercentage;
        transform.position = startingPos + offset;
        
    }
}

Privacy & Terms