Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Liam Andersson
Liam Andersson
1,396 Points

I have a question about C#

I have a question about the code:

movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

What do the 0.0f mean? Does it mean that it should stay at the ground (y)? But if so why isnt it by the moveVertical variable? Vertical is up and down and horizontal is left and right..

Am I stupid?

I'm not sure if you are asking this question in the context of a particular video or not, but if you are, please link to it so we can examine the method context.

Otherwise, 0.0f is a way of denoting floating point notation. Here was a useful answer from stack overflow.

"Without a suffix, a literal with a decimal in it (123.0) will be treated as a double-precision floating-point number. If you assign or pass that to a single-precision variable or parameter, the compiler will (should) issue a warning. Appending f tells the compiler you want the literal to be treated as a single-precision floating-point number."

https://stackoverflow.com/questions/14302898/is-it-better-to-write-0-0-0-0f-or-0f-instead-of-simple-0-for-supposed-float-or

Also, as to if you are stupid:

No. Just...nope. :)

Liam Andersson
Liam Andersson
1,396 Points

Thanks for your answer, well i was watching this course: https://teamtreehouse.com/library/how-to-make-a-video-game-2 I have problems understanding almost all of it, should I start with the #C basics instead? Because I have problems with the quaternions.. I really got stuck there. Any advice?

Here is the video about quaternions: https://teamtreehouse.com/library/quaternions

It's a pro/con situation. The course says it was designed for beginners who have never programmed before, so it could very well be OK to stay the course and finish it out. However, from what I can tell, you will be learning coding concepts alongside learning Unity engine, and that may be more than you want to wrap your head around at the moment.

The benefit of finishing the How to Make a Video Game course is that it is interesting to learn game design and you'll have a leg up if thats the direction you want to end up going. The benefit of going to a basics course is it won't include learning Unity engine alongside it, so you can focus more on just the language. If you think your interest level will be fine if you just take a basics course, perhaps start with that. In the end, only you'll know what you need to help you learn.

I'll check into the video and see if I can answer your original question.

1 Answer

From the unity Documentation:

"Representation of 3D vectors and points.

This structure is used throughout Unity to pass 3D positions and directions around. It also contains functions for doing common vector operations.

Besides the functions listed below, other classes can be used to manipulate vectors and points as well. For example the Quaternion and the Matrix4x4 classes are useful for rotating or transforming vectors and points."

https://docs.unity3d.com/ScriptReference/Vector3.html

When creating a new Vector3, we need to provide x, y, and z. coordinates. In your shared code, the 0.0f is the y coordinates, per the constructor documentation linked below.

https://docs.unity3d.com/ScriptReference/Vector3-ctor.html

Liam Andersson
Liam Andersson
1,396 Points

Thanks for the comment! I will actually continue through the course because I'm interested in video games. But I will also check the C# Basic course. Thanks again for your help!

Yep, no problem. Good luck!