So I have a gun for a game I’m working on where the bullets travel in a sine wave, however the idea I want to implement is to have the bullets y-value smoothly increase the size of the sine wave in a way that’s not noticeably jagged. So the sine wave starts small and then increases reaching a maximum point.
The following code is here:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletMove : MonoBehaviour {
public Vector3 startPosition;
public Vector3 endPosition;
public Vector3 bend;
public float bendRatio;
public float amp;
// Use this for initialization
void Start () {
bendRatio = 1;
amp = 5;
startPosition = transform.position;
endPosition = new Vector3 (5, 0, 0);
bend = new Vector3 (0, bendRatio, 0);
}
// Update is called once per frame
void Update () {
Vector3 currentPosition = Vector3.Lerp (startPosition, endPosition, Time.time);
currentPosition.y += bendRatio* Mathf.Sin((Time.time * amp) * Mathf.PI);
transform.position = currentPosition;
}
}
I tried doing this in a new Unity file just to see if I could get the sine wave to increase but after trying numerous things I wasn’t able to get it to do what I want. I’m not sure when to update my bendRatio variable to increase the size of the sine wave. I can’t do it every frame, not even by 1 or the sine wave gets out of control. I’d also like if possible to hit predetermined heights just in case the sine wave gets out of control. So bendRatio would start at 1, then go to 1.5 and then 2 etc, but when that would be updated I don’t know.
Ideally, I would like the wave to create this shape.
Please let me know if this is even possible.