Hi! Don’t know if anybody has figured this out before (probably have).
I came up with this method to make the smooth sin movement. To me, it seems easier than in the course.
Please take in mind that I’m still quite new to programming.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveBlock : MonoBehaviour
{
[Range(-5, 5)] [SerializeField] float momevent;
Vector3 position = new Vector3(-25.96f, 13.57f, 0f);
float sineInput;
float sinWave;
float timer;
[SerializeField] float movementRange = 5f;
[SerializeField] float movementSpeed;
// Start is called before the first frame update
void Start()
{
transform.position = position;
}
// Update is called once per frame
void Update()
{
transform.position = position;
timer = timer + Time.deltaTime + (movementSpeed/100);
if(timer>=2*Mathf.PI)
timer = 0;
sineInput = timer;
sinWave = Mathf.Sin(sineInput);
momevent = sinWave * movementRange;
position = new Vector3(-25.96f, 13.57f + momevent, 0f);
}
}
Right now it only works on the Y axis.