Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 /
This question was closed Mar 28 at 04:36 PM by up2004523 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by up2004523 · Mar 24 at 02:55 PM · vector3transform.position

Transform Position

Hello. For a school project we had to create our own Vector 3 In unity and use it later to move objects. The goal was to make a sphere move to the position of the cube using our own vector and the subtraction of vectors (SubtractVector Function). But every time I try to set the destination of Sphere to the one I calculated on the SubtractVector function it shows me an error of "Cannot implicity convert type "MyVector3" to "UnityEngine.Vector3". Can someone give me some help..?

My code:

     public GameObject Cube;
     public GameObject Sphere;
 
     private void Start()
     {
          Sphere = GameObject.Find("Sphere");
 
          
     }
 
     private void Update()
     {
         Vector3 test = new Vector3(1, 1, 1).normalized;
           
 
         
         if (Input.GetKeyDown("space"))
         {
 
             MyVector3 cubePos = new MyVector3(Cube.transform.position.x, Cube.transform.position.y, Cube.transform.position.z);
             MyVector3 spherePos = new MyVector3(Sphere.transform.position.x, Sphere.transform.position.y, Sphere.transform.position.z);
             
             MyVector3 move = MyVector3.SubtractVector(spherePos, cubePos);
 
 
             Sphere.transform.position = move;
 
 
 
         }
 
        
     }
 }


Own Vector code:

  public float x,y,z;
 
     public MyVector3(float x, float y, float z)
     {
         this.x = x;
         this.y = y;
         this.z = z;
        
 
         
     }
 
   public static MyVector3 SubtractVector(MyVector3 vec1, MyVector3 vec2)
     {
         MyVector3 rv = new MyVector3(0, 0, 0);
 
         rv.x = vec1.x - vec2.x;
         rv.y = vec1.y - vec2.y;
         rv.z = vec1.z - vec2.z;
 
         return rv;
     }


Thank you.

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

  • Sort: 
avatar image
0
Best Answer

Answer by rh_galaxy · Mar 24 at 03:10 PM

You need to create the Vector3 and Init it yourself, it can't be automatic.

 Sphere.transform.position = new Vector3(move.x, move.y, move.z);
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 up2004523 · Mar 24 at 03:28 PM 0
Share

It works perfectly. Thank you so much

Follow this Question

Answers Answers and Comments

167 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 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 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

Simple script to move object doesn't work 1 Answer

Cant change transform.position of gameobject 1 Answer

Vector3 math problem? 1 Answer

How to change transform.position.x to go backwards at specific instance? 2 Answers

Get closest Vector3 position from a GameObject and two Transforms (and the line inbetween them) 2 Answers


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