Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GeneralValkova · Nov 23, 2014 at 06:54 AM · javascriptpositionvector3touch

Vector2 Error when Declaring new Vector3

Hello,

I'm currently working on a project that uses the ScreenToWorldPoint function to develop a touch control system.

Here's the line in question:

 var touchPosition : Vector3 = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, 0, touch.position.z));

I want to use "Camera.main.ScreenToWorldPoint" to create a new Vector3. However, my console returns the following error when I compile the code.

Error BCE0019: 'z' is not a member of 'UnityEngine.Vector2'. Did you mean 'x'? (BCE0019).

I think the issue is that it believes I want a 2d vector when in reality I want to create a 3d vector.

Here's the complete code for reference.

 function Update () {
   var object : GameObject;
       for(var touch : Touch in Input.touches){
       if(Input.touchCount > 0) {
           // Check for Touch on Screen.
 
         if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
             var touchPosition : Vector3 = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, 0, touch.position.z));
             // Create Vector from Touch Position, and "ScreenToWorldPoint" Function.
             transform.position = Vector3.Lerp(transform.position, touchPosition, Time.deltaTime);
             // Smoothly Translate GameObject according to Last Frame, Touch Position, and Time.
             transform.LookAt(touchPosition, Vector3.up);
             // Orient GameObject according to Touch Posiition.
             }
         }
     }
 }

I'm sure there's something right in front of me that I'm missing but I've been fighting with this for a little too long so I'm turning to the community!

Thanks for any help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jeff-Kesselman · Nov 23, 2014 at 06:55 AM

touch is a Vector2. use 0 for the third parameter

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GeneralValkova · Nov 23, 2014 at 07:01 AM 0
Share

Thanks for your reply!

That did remove my error, however, $$anonymous$$y intention was to have the object move on the XZ plane. Wouldn't declaring the z parameter 0 meanthe object would only transform on the XY plane?

Thanks again!

-Trent

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Array.Push() for Vector3[] or how to add items to Vector3 array without knowing index 1 Answer

Vector3 Transform.Position Not Working 2 Answers

JS access spherecast position 1 Answer

How to get my character to move left to right? 0 Answers

Vector3.lerp doesn't work 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges