Hi, superNoob here; I am following a book (Learning C# Programming With Unity 3D By Alex Okita[AKD]) trying to learn C# w/ Unity. Bellow is what I am instructed to put in the script( I am using Microsoft Visual Studio). public class NewBehaviourScript : MonoBehaviour { public float Control; public float OtherControl; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { float x = Mathf.Sin(Control) * OtherControl; float y = Mathf.Cos(Control) * OtherControl; float z = Control * OtherControl; transform.position = new Vector3(x, y, z); } } I do so and change Control and OtherControl values in the inspector. The sphere jumps when I change the values, just jumps from one spot to another. The book says "Play with this for a little bit; just make sure OtherControl is a value other than 0. You should see a spiraling ball moving around, thanks to Mathf.Sin() and Mathf.Cos(). Basically, these two Mathf functions return the sine and cosine of control." yet the ball does not spiral or move acros the screen. Am I understanding this wrong? should the ball just jump or should it actually move and spiral.
Please use code formatting when posting code. Most of us will ignore posts that simply paste unformatted code. What values are you entering for Control and OtherControl in the editor?
OK, I will use code formatting in the future. I did not use the editor. In the Inspector(New Behavior Script tab that was created when I dragged the script over the ball/sphere) I used any number of values for Control and OtherControl. 0 to 9 for Control and 1 to 9 for OtherControl. The ball just jumps around when i change values.
The ball would only spiral if the value of Control were changing every frame. I see no code to make it do that. Either you or the author (or possibly the printer) have made a mistake. Go back and double-check your code against the book carefully; and if they're still the same, then see if you can fix it yourself, by putting in one more line of code in Update() that adds a little bit to Control.
I have copied the code from the PDF book and checked it a few times over to confirm it is the same. I can see what you mean by putting in one more line of code in Update(), unfortunately i don't know how Can you suggest a C# book for total beginners?
While I respect that you are one of the few people who like to read books (I am too!), I don't know a good C# one, though I bet a few minutes of browsing and reading reviews at Amazon would turn one up. But you could certainly do worse than working your way through the Learn CS tutorial online. And incidentally, you're smart to realize that this is the next step. Unity is not a drag-and-drop development environment; you have to write code to get anything done. So learning at least the basics of C# is a necessity. Good luck, and post again if you get stuck!
You mentioned "I used any number of values for Control and OtherControl. 0 to 9 for Control and 1 to 9 for OtherControl." but your code doesn't show that. Where are you setting the values? What if you tried float x = Mathf.Sin(Control) * OtherControl; float y = Mathf.Cos(Control) * OtherControl; float z = Control * OtherControl; transform.position = new Vector3(x, y, z); Control += 1.0f;
I have put those numbers in the public float Control and OtherControl that opens up in the Inspector, not in the script. I will try as you suggest.
I just checked out the book on Amazon, do you have the Github link for the files mentioned in the book?
Hey! it worked the ball started spiraling in one direction, at +=1.0f the ball moves very fast but allways in one direction on the Z axis. Chaning it to +=0.2f makes the ball spiral much slower but on the same axis. Cool, thank you! Can you explain in a few short words what the 'f' represents? No, i dont have any links from the book. I'm only in chapter 3 but the book gives me no links/files to download, appart from instructing me to dl unity3d in chapter 2.
Google says https://github.com/JXPorter/OkitaUnity It hasn't been updated in awhile. And the f notation means float https://stackoverflow.com/questions/11519743/why-is-the-f-required-when-declaring-floats