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
1
Question by Arishtanemi1998 · Sep 11, 2014 at 05:41 PM · transformpositionvector3coordinates

split vector3 coordinates in to x,y,z

hey i need to get the x,y and z values of the coordinates separately so that i can modify them and get the new coordinates for position. can u tell me hoew to implement that in javascript.the code that i am currently using, displays the coordinates of a moving object.i need to separate them and modify them like x+4 or y-3 and then use them in transform.position.thanks in advance

my current code:- //Unity will constantly check the position of the GameObject.function Update () {

//Creates a variable to check the objects position.

myPosition = transform.position;

//Prints the position to the Console.

Debug.Log(myPosition); }

Comment
Add comment · Show 2
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 gjf · Sep 11, 2014 at 03:27 PM 0
Share

1) please format your code.

2) Vector3 has 3 components (shocker) called x, y & z ... depending on what you want to do, try something like:

 Debug.Log(myPosition.x);

this is surprisingly helpful.

avatar image tanoshimi · Sep 11, 2014 at 05:46 PM 0
Share

Also, if you want to modify the transform.position of x+4, y-3 as in your example, you don't need to access the seperate components - try this:

myPosition = transform.position + Vector3(4, -3, 0);

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by jtsmith1287 · Sep 11, 2014 at 09:31 PM

First off, make sure to keep your posts formatted. People don't want to read code when it just looks like sloppy plain text.

Second, the solution is super simple.

 myPosition.x += 4
 myPosition.y -= 3

You can also add multiple Vector3 objects together.

 newPos = Vector3(4, -3, 0);
 myPostion = transform.position;

 finalPosition = newPos + myPosition;

or

 finalPosition = transform.position + Vector3(4, -3, 0);


I would also encourage you to spend time reading through documentation on the Unity wesbite. A quick server for Vector3 would have shown you everything I just posted.

Comment
Add comment · Show 2 · 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 Arishtanemi1998 · Sep 12, 2014 at 01:37 PM 0
Share

thanks jtsmith1287 it worked out.ill make sure of your advice too next time

avatar image jtsmith1287 · Oct 16, 2014 at 09:22 PM 0
Share

Would you $$anonymous$$d selecting this as the accepted answer please? :)

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

Vector3 sets to different coordinates than specified 1 Answer

Issue's With Positioning 0 Answers

Offset against Rotated Object,Applying Offset to a Rotated Transform 1 Answer

Reposition to minimum distance from target 2 Answers

Play animation as the value changes from 0 to 1 with changing GameObject's position in unity 0 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