Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 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 /
avatar image
0
Question by Alienjesus · Feb 20, 2011 at 06:56 PM · javascriptgameobjectpositioncoordinates

Finding position of a game object

Hi,

I'm a complete beginner at Unity, and I've just started attempts at coding (I'm using it for my degree project, perhaps unwisely as I feel completely in over my head). My game aims to take the position of an object (which is controlled by a fiduciary marker) and being able to manipulate other game objects positions with it. However, I can't figure out even the basics so far, as I'm struggling to find the necessary javascript code to find the x and y co-ordinates of the object (it moves on a 2D plane, so Z isn't an issue). What is the code I need?

I have an idea how the code should look, but I'm just struggling to figure out how you'd write it in Unity. Heres a rough example of what I want it to do (obviously not in code yet).

Find the Xposition and Yposition of this gameObject (the one controlled by the fiducial, which I hope to apply this script to) For Zpos = 0 to 150, (this allows for depth) If a gameObject exists at (Xpos, Ypos, Zpos) Then that gameobject should gain an effect to show it has been found (glowing perhaps) If object is found, stop loop.

Sorry for being a completely beginner, I understand people normally come for help with a bit more than this.

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
8
Best Answer

Answer by Caiuse · Feb 20, 2011 at 06:59 PM

This will print the GameObject that it is attached to position in the Console. You could use that information for any other purpose

//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);
}

To get started:

http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

http://unity3d.com/support/documentation/ScriptReference/

Comment
Add comment · Show 7 · 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 Alienjesus · Feb 20, 2011 at 07:19 PM 0
Share

Thanks, I'll check those links out. I've never used Javascript before, only a little Visual Basic, so I was kinda lost. All of my searches were fruitless too.

avatar image Caiuse · Feb 20, 2011 at 07:24 PM 0
Share

I've only just started with javascript within the last month, I found UnityStudent a tutorial video website a brilliant start for learning. I was in noway a coder before, but know i know my way around(ish)

avatar image Alienjesus · Feb 20, 2011 at 07:50 PM 0
Share

I'll check that out too thank you :D

Is there a way to pull out just one of the transform values (just x or y for example)? I imagine it'd be something like transform.position.something right? After that, no more annoying noobie questions for today, I promise.

avatar image Caiuse · Feb 20, 2011 at 09:01 PM 0
Share

transform.position.y (or x, z) :D np

avatar image Alienjesus · Feb 20, 2011 at 09:40 PM 0
Share

So I got the code I needed working so far, and I tried it again with rotation, but the numbers come out as decimal points ins$$anonymous$$d of degrees. Thats fine, but why are there four of them? Obviously the first 3 are x,y and z rotation, so whats the fourth value?

Oh, nuts, I guess I lied about no more noobie questions for today >_<

Show more comments

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

No one has followed this question yet.

Related Questions

Spawn game object in random position on screen 1 Answer

Erasing a gameobject if you have the coordinates. 3 Answers

Change Position of an object 1 Answer

Instantiate as a child at position 2 Answers

Position of a GameObject 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