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

Game Development How to Make a Video Game Player Input and Cameras Gather Player Input

Why do we need a new Vector3

So I understood this entire video with the exception of when we created a new Vector3 in the update method. We had it up top when we made it private. So why did we have to write it as new? Why didn't we have to do that with the floats but we did with the Vector3?

2 Answers

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hi Joshua,

I haven't got the code in front of me. But it sounds like up the top you are creating a new private variable and telling the program it is of the type 'Vector3'.

Vector3 isn't a variable, but a Struct. You have to create a new Vector3 rather than just assigning it. When we use the 'new' keyword before Vector3 we are creating a new copy of the Vector3 Struct.

Hope this helps explain it a little more.

It does thank you for your help.