[help] Oscillator problem when running the game

When hitting Play in Unity, the oscillating objects jump or “teleports” to the middle of the path on the movement vector, and then continue to oscillate normally. Is there a problem with my Oscillator script or is the problem the starting position of the object in Unity?

Hi jeeps0n,

Welcome to our community! :slight_smile:

The problem is indeed in the Oscillator class. You did not do anything wrong, though, because it is also part of Rick’s algorithm.

The idea is the following: We want to move the object from a starting position to a target position. And we do that with the following function (in pseudo code!): newPosition = startingPosition + x * offset where x is a value between 0 and 1 (0% and 100%). Rick named the offset movementVector.

If you log the movementVector into your console, you’ll notice that it does not start at 0 but at 0.5. That’s why your object teleports.

Since the solution is rather simple, I’m leaving this challenge for you. If you need help or if you managed to solve the problem yourself, please let me know. :slight_smile:


See also:

I feel kinda silly, but I still can’t figure this one out :frowning: Could you give me another hint?

Well, a hint would be to read my explanation in this thread:

Then you could go to Desmos | Graphing Calculator and check the following:
image

The function at the bottom is our function in the code: c = (sin (x) + 1) * 0.5. For some reason, I wasn’t able to put it in one line, hence the b in the third equation.

If you compare these three and disable a and b, you’ll see that c starts at 0.5 on the y-axis if x = 0.

You can also see the offset. Use Desmos to move the c-wave on the x-axis until the y-value is 0 if the x-value (in the graph) is 0. Instead of manipulating c, create a new function d similar to what I showed you with a, b, c. If you got the desired result on Desmos, you will very likely be able to apply this in your C# code.

I hope this helped as a hint. :slight_smile:


[Edit:] Paste this into desmos to get the relevant parentheses: y=\ a\ \left(\sin\left(\frac{\left(x-h\right)}{b}\right)+k\right). Then click ‘All’ to add a slider for all variables. Modify the function until you get result c, then try to ‘move’ the wave. If you need more parentheses but cannot make them appear in Desmos, modify what you pasted there.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms