Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created August 15, 2019 16:41
Show Gist options
  • Save smkplus/3d27e64415a07684c734515df8811c32 to your computer and use it in GitHub Desktop.
Save smkplus/3d27e64415a07684c734515df8811c32 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SineMovement : MonoBehaviour
{
public float MoveSpeed = 5.0f;
public float frequency = 20.0f;
public float magnitude = 0.5f;
private Vector3 axis;
private Vector3 pos;
void Start()
{
pos = transform.position;
axis = transform.up;
StartCoroutine(Delay());
// Time.timeScale = 3;
}
bool landed = false;
public float timer;
IEnumerator Delay()
{
while (true)
{
if (!landed)
timer += .01f;
pos += transform.forward * Time.deltaTime * MoveSpeed;
float number = Mathf.Abs(Mathf.Sin(timer * frequency)) * magnitude;
transform.position = pos + axis * number;
// Debug.Log(number / magnitude);
if (number <= .1f && !landed)
{
Debug.Log("Test");
yield return new WaitForSeconds(1);
landed = true;
}
landed = false;
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment