• 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 javanoob · Nov 21, 2012 at 03:30 AM · transformvector3local

Move object hierachy downwards instantly by x amount ?

Hi there ,stupid question time lol :) I want to move an object including its two children down (say 1000) units instantly . at the moment I am positioning the object in the editor 1000 units UP ,then in my script It moves down 1000 units when triggered with this command

GameObject.Find("Ckp2").transform.position = Vector3(1070,67,530); // it was at (1070,1067,530) This works perfectly but ,and heres the stupid question lol how can i place my checkpoint objects anywhere (x,y,z) then move them downwards (-y) ?

I tried transform.localposition but it seemed to move the object elsewhere to just downward ,I know this is an obvious answer lol ,what am I doing wrong please :)

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

Answer by javanoob · Nov 21, 2012 at 04:41 AM

GameObject.Find("Ckp2").transform.Translate(0, -900, 0);

transform.Translate LOL ,I knew it was something obvious :) Admins feel free to delete my stupid question :p

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 sparkzbarca · Nov 21, 2012 at 03:32 AM

GameObject object = GameObject.find("Ckp2");

float distance = 1000;

object.transform.position += -object.transform.up * distance;

mark as answered and happy coding. :)

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
Wiki

Answer by javanoob · Nov 21, 2012 at 03:53 AM

:O getting a couple of errors ? I should have said my code is JS is your snippet in C# by any chance ?

function OnTriggerEnter(hit : Collider){

 if (hit.gameObject.name == "Cube1"){
               ckp=ckp+1;
        GameObject object = GameObject.find("Ckp2");
        float distance = 1000;
        object.transform.position += -object.transform.up * distance;


gives me --- Assets/Checkpoint.js(76,22): UCE0001: ';' expected. Insert a semicolon at the end. its the GameObject object = GameObject.find("Ckp2");

Comment
Add comment · Show 3 · 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 javanoob · Nov 21, 2012 at 04:18 AM 0
Share

Basically i have a racing game where all the checkpoints apart from the first one are positioned 1000 units up in the air (out of sight) and when I hit checkpoint 1 it goes up 1000 and checkpoint 2 comes down 1000 ,It works perfectly (anti cheat :) ) but I have to manually change all the values of each checkpoint each time I make a new track ,so I was just looking for the command that lowers the checkpoint by 1000 units relative to whereever it happens to be placed (lazy ,but I wanted it to be perfect lol) . your code just kept asking for semi colons where afaik they shouldn't be placed ,so im lost lol :( It doesent matter if it cannot be done ,its only 10 checkpoints to be changed for each new track ,I just presumed there would be a quicker way .

avatar image sparkzbarca · Nov 21, 2012 at 04:27 AM 0
Share

javascript would be something like

var object = ...

var distance = ...

I believe thats the only change needed in this case but i'm not sure

I don't program java so I can only infer the syntax based on code i've seen

avatar image javanoob · Nov 21, 2012 at 04:53 AM 0
Share

GameObject.Find("Ckp2").transform.Translate(0, -900, 0);

That did the trick perfectly :) now i can move the checkpoints around and not have to find their coordinates :) Sweet :) Thanks for the answer tho :)and by the way uber quick response too :)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

getting object local direction? 1 Answer

Moving a Platform 1 Answer

Why using = isn´t fast enough for changing Vector3 values from the transform? 2 Answers

Transformations 2 Answers

gravity causes transform.position not to work 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