i thought you’re trying to keep things simple for now but this is complex stuff here. Anyways i followed along and everything works , im getting no errors but this is very confusing, is there a simpler way?
You are not alone.
Yeah I especially didn’t understand the math conversation around the oscellation but I do respect the “you don’t have to know how the car works to drive the car” argument - so although I can’t duplicate what was taught, I can totally cut and paste it lol.
you’re right, im with you on the car example. I don’t fully understand the math in the code but i know how to use it in my game lol. So far im loving this course also Ben and Rick are amazing instructors.
Yeah I don’t always understand what I’m doing but I am DOING so that’s good. You’re right, these guys are good instructors and I’m sure as time goes on we will grasp the concepts.
I blew my project up last night, thank God for frequent SourceTree commits lol.
Well I’m not perfect at the math things, so after understanding what is needed to make the obstacle move… I tried to write my own “obstacle movement” without the math function… not perfect but after doing this I got the understanding for the solution of Ben… so maybe it helps a littlbe bit:
public class Oscillator : MonoBehaviour {
[SerializeField] Vector3 movementVector;
// remove from inspector later
// some testing
[SerializeField] float oscSpeedFactor = 0.1f;
[Range(0.0f,1.0f)][SerializeField] float currentOscValue = 0.0f;
float oscValueStart = 0.0f;
float oscValueEnd = 1.0f;
Vector3 startingPos;
enum oscDirection {POSITIVE, NEGATIVE, STOP };
oscDirection oscillationDirection = oscDirection.POSITIVE;
// Use this for initialization
void Start () {
startingPos = transform.position;
}
void OscilatePositive ()
{
if (currentOscValue >= oscValueEnd)
{
oscillationDirection = oscDirection.NEGATIVE;
}
currentOscValue += Time.deltaTime * oscSpeedFactor;
}
void OscilateNegative ()
{
if(currentOscValue <= oscValueStart)
{
oscillationDirection = oscDirection.POSITIVE;
}
currentOscValue -= Time.deltaTime * oscSpeedFactor;
}
// Update is called once per frame
void Update () {
switch(oscillationDirection)
{
case oscDirection.POSITIVE:
OscilatePositive();
break;
case oscDirection.NEGATIVE:
OscilateNegative();
break;
case oscDirection.STOP:
break;
}
Vector3 offset = movementVector * currentOscValue;
transform.position = startingPos + offset;
}
}