Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
-1
Question by Paramotion · Jun 03, 2017 at 09:03 PM · vector3convertvoid

Cannot implicitly convert type void to UnityEngine.Vector3

So, I'm currently porting some js scripts from Unity3D examples to C#, and one of the errors I'm getting is this : Cannot implicitly convert type void to UnityEngine.Vector3

Here's a screenshot and the script by the way

alt text

 void Update () {
 
 //Character movement direction
        motor.movementDirection = Input.GetAxis ("Horizontal") * screenMovementRight + Input.GetAxis ("Vertical") * screenMovementForward;
        
        //Make sure the direction vector doesn't exceed a length of 1
        // so the character can't move faster diagonally than horitonally or vertically
        if (motor.movementDirection.sqrMagnitude > 1)
        {
            motor.movementDirection.Normalize();
        }
 
        //Character facing direction and screen focus point
 
        //First update the camera position to take into account how much the character moved since last frame
        //mainCameraTransform.position = Vector3.Lerp (mainCameraTransform.position, character.position + cameraOffset, Timpe.deltaTime * 45.0f * deathSmoothoutMultiplier);
 
 
        //Set up the movement plane of the character, so screenpositions
        //can be converted into world positions on this plane
        //playerMovementPlane = new Plane (Vector3.up, character.position + character.up * cursorPlaneHeight);
 
        //optimization (instead of newing Plane)
        playerMovementPlane.normal = character.up;
        playerMovementPlane.distance = -character.position.y + cursorPlaneHeight;
 
        //used to adjust the camera based on cursor
        Vector3 cameraAdjustmentVector = Vector3.zero;
 
        float axisX = Input.GetAxis("LookHorizontal");
        float axisY = Input.GetAxis("LookVertical");
        motor.facingDirection = ((axisX * screenMovementRight) + (axisY * screenMovementForward));
 
        cameraAdjustmentVector = motor.facingDirection;
 
        //On PC, the cursor point is the mouse position
        Vector3 cursorScreenPosition = Input.mousePosition;
 
        //Find out where the mouse ray intersects with the movement plane of the player
        Vector3 cursorWorldPosition = ScreenPointToWorldPointOnPlane (cursorScreenPosition, playerMovementPlane, mainCamera);
 
        float halfWidth = Screen.width / 2.0f;
        float halfHeight = Screen.height / 2.0f;
        float maxHalf = Mathf.Max (halfWidth, halfHeight);
 
        //Acquire the relative screen position
        Vector3 toMath = (halfWidth, halfHeight, cursorScreenPosition.z);
        Vector3 posRel = cursorScreenPosition - (Vector3 (halfWidth, halfHeight, cursorScreenPosition.z));
        posRel.x /= maxHalf;
        posRel.y /= maxHalf;
 
        cameraAdjustmentVector = posRel.x * screenMovementRight + posRel.y * screenMovementForward;
        cameraAdjustmentVector.y = 0.0f;
 
        //The facing direction is the direction from the character to the cursor world position
        motor.facingDirection = (cursorWorldPosition - character.position);
        motor.facingDirection.y = 0;
 
        //Draw the cursor nicely
        HandleCursorAlignment (cursorWorldPosition);
 
        //Handle camera position
 
        //Set the target position of the camera to point at the focus point
        Vector3 cameraTargetPosition = character.position + initOffsetToPlayer + cameraAdjustmentVector * cameraPreview;
 
        //Apply some smoothing to the camera movement  WTF IS "ref" in cameraVelocity
        mainCameraTransform.position = Vector3.SmoothDamp (mainCameraTransform.position, cameraTargetPosition, ref cameraVelocity, cameraSmoothing);
 
        //Save camera offset so we can use it in the next frame
        cameraOffset = mainCameraTransform.position - character.position;
 }
problemu.png (102.7 kB)
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
1
Best Answer

Answer by FM-Productions · Jun 03, 2017 at 09:17 PM

I cannot find the ScreenPointToWorldPointOnPlane function in the docs, so I guess it is a custom function written by you?

The error message is very clear: you want to assign a void as value to a Vector3. The thing is, the function ScreenPointToWorldPointOnPlane returns void, that means it returns nothing. Thus, you cannot assign it as value to the Vector3 variable. You would have to rewrite the function to return the desired vector of the point position.

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 Paramotion · Jun 03, 2017 at 10:18 PM 0
Share

You were right! It was a custom function passing "void" ins$$anonymous$$d a "Vector3". Problem solved, thank you so much!!

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

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I use the Vector2/Vector3 operator (converting Vector2 to Vector3 and vice versa) 3 Answers

Using a variable as a components for Vector3 1 Answer

convert string to a array of vector 3 3 Answers

C# Convert Vector3[] to Vector2[] 3 Answers

how to convert the angle to roatation? 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