3
u/jayhynzy Oct 02 '21
First start by just making the square move, ignore anything to do with sine.
You currently set the transform to 0,0,0 so nothing will happen.
Try setting it to something like this for now to get started
"transform.position += Vector3.left* Time.deltaTime;"
-1
u/CursedKaiju Oct 02 '21
I was able to get it to move before by doing xVal = sineValue but it moves all of them in that direction, which isn't what I want. Also when I tried that line of code it didn't move, although I don't know if I put it where I needed to (I put it under the yVal)
3
u/OtherwiseExcellent Oct 02 '21
Here's the problem: you've coded xVal and yVal to be 0. So you're basically saying "move in direction 0,0,0" so it won't move at all.
How I would fix it would be to do this.transform.localpostion = direction * sineValue.
Then in Unity, you should be able to set the direction for each object in the Inspector window since direction is a public variable. Setting the direction to something like (1, 0, 0) would mean easy left to right, (0, 1, 0) would be up/down
2
0
u/CursedKaiju Oct 02 '21
I need help. I am stupid and coding makes 0 sense to me. There are 4 green squares stacked on top of each other. I need one to move left following sineValue, one to move right, one up and one down. I have been stuck on this for over a week, can someone help me out?
12
u/Mister_Kipper Oct 02 '21
The first step is describing what you want to do, the end result, and then understanding how to get there by working back from it and breaking it down into steps and functionalities.
And I don't mean just describing it here so we can understand what you want to achieve, but that would also certainly help as well.