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 Shirou14 · Oct 27, 2012 at 10:34 PM · positionvector3scale

How do you move an object relative to a plane's global scale?

Okay, so I have a question and I've done my looking, but I haven't found any answer for my particular issue.

I have a plane, it's at a scale of 1x1x1. I also have a game object, an empty one. What I want to do is position this game object in relation to the plane's scale using code. Let's say I want the game object to sit neatly at the plane's bottom left-hand corner looking down along the Y axis. What I would like to do is math similar to this:

 //please imagine this math is completed for each vector axis, otherwise I'm going to have a very wide post.
 Vector3 goPosition = new Vector3 (plane.transform.position - (plane.transform.scale * 0.5))

theoretically that math should have my game object starting in the middle of the plane, then moving happily along half of the plane to the left, and then half of the plane down, reaching the corner.

the problem is, however, that the actual scale of the plane isn't relative to the world or the Vector3 Co-ordinates. so instead of my object now being at the corner of the plane, it sits slightly off-center. Is there anyway to do what I desire based on the scale of the plane? or anyway to get the plane's scale in relation to the Vector3 Co-ordinates?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Shirou14 · Oct 28, 2012 at 04:00 AM

So hey guys, I was given an answer elsewhere where instead of using plane.transform.localScale, I should instead use plane.transform.renderer.bounds.size, and it works very well.

if you guys can think up a better solution though, I'm all ears!

thanks!

Shirou

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 swatmaster69 · Oct 29, 2012 at 04:20 AM 0
Share

That sounds interesting. I might try it for my sort-of tennis court in my game.

avatar image
0

Answer by swatmaster69 · Oct 28, 2012 at 04:01 AM

I believe the default size of the plane object is 10m x 10m, so you could do, say

 float planeWidth =  10 * plane.scale.x;  
 float planeLength = 10 * plane.scale.z;

and then use those variables to move things around:

 Vector3 goPosition = new Vector3(plane.position.x - (planeWidth / 2), ...
Comment
Add comment · 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
0

Answer by MountDoomTeam · Oct 28, 2012 at 03:12 AM

if you make the object child of the plane, then it will always stay in the same place relative to the plane it's size will also be relative to the plane size.

so you want to put your object at (-1, 0, .1)

then you do

 pos= Vector3 (-1*plane.transform.localScale*.5+plane.transform.position,
 plane.transform.position,
 .1*plane.transform.localScale*.5+plane.transform.position)
Comment
Add comment · 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

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

11 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

Related Questions

Scale and position object between two points 1 Answer

Position + Vector3 doesn't return correct values 1 Answer

Scale mesh between two Vectors 1 Answer

How to align the bottom of a GameObject with the ground? 1 Answer

UnityEngine.Component:get_transform() Error 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