Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by JeffHardddyyy · Nov 27, 2016 at 03:22 PM · transformvector3transform.position

Vector 3 moving to certain place?

So I have this code :

         if (Input.GetKey(KeyCode.I))
         {
             transform.position = new Vector3(0, 10, 0);
             Debug.Log("Executed");
         //this isn't what I want, this is only to :
       // help other people and do what I originally want, something very similar.

}

And I would like it to instead of going to 0,10,0

I want it to go up 10 than it's original position.

Atleast know what to do in order

EDIT : Please note that this is gonna be a moving object

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

2 Replies

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

Answer by Runalotski · Nov 27, 2016 at 03:38 PM

To set the position relative to its current position use

 transform.Translate(new Vector3(0,10,0));
Comment
Add comment · Show 8 · 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 Bunny83 · Nov 27, 2016 at 04:03 PM 0
Share

Note: This will move along the local up vector of the object and not along the world up vector. This might be relevant when the object is rotated.

avatar image JeffHardddyyy · Nov 27, 2016 at 04:06 PM 0
Share

Anyway to make it return to a spot ?

Because what I'm doing is trying to get it into a kicking way. So when it gets on collision or something, It returns back under the leg.

avatar image Runalotski JeffHardddyyy · Nov 27, 2016 at 05:34 PM 0
Share

to make it return you will run code with the following built in function

 Void OnCollisionEnter(Collision col)
 {
     if(col.transform.tag == "Enemy")
     {
          Debug.Log(transform.name + " hit an Enemy");
          transform.position = resetPosition;
     }
 }


Now I don't know what the original position is that you need to set and you also need a rigid body on that object to have this function call

avatar image JeffHardddyyy Runalotski · Nov 27, 2016 at 05:44 PM 0
Share

Everything works after trying to debug most of it (I'm using Visual Studios)

So I got :

 private void OnCollisionEnter(Collision collision)
 {
     if (collision.transform..tag = "Enemy")
     {
         Debug.Log(transform.name + " hit an Enemy");
         transform.position = resetPosition;
     }

}

And I don't know what resetPosition is?

Show more comments
avatar image JeffHardddyyy · Nov 27, 2016 at 09:30 PM 0
Share

@Runalotski but It says 'The name resetPosition does not exist in the current context'

avatar image Runalotski JeffHardddyyy · Nov 27, 2016 at 09:32 PM 0
Share

That is correct you have to replace it with something that makes sense to your project.

avatar image JeffHardddyyy Runalotski · Nov 27, 2016 at 09:47 PM 0
Share

That pretty much works to my standards,

I used : private void OnCollisionEnter(Collision collision) { if (collision.transform.tag == "Enemy") { Debug.Log(transform.name + " hit an Enemy"); Vector3 resetPosition = default(Vector3); transform.position = resetPosition; } }

Thanks for answering @Runalotski.

avatar image
2

Answer by OneEyeMaker · Nov 27, 2016 at 03:34 PM

Maybe, it helps you:

 transform.position += new Vector3(0.0F, 10.0F, 0.0F);

Also, if your GameObject has Rigidbody component, you can do this:

 Rigidbody rigidbodyComponent = GetComponent<Rigidbody>();
 rigidbodyComponent.AddForce(new Vector3(0.0F, 10.0F, 0.0F));

Read more about Rigidbody in documentation.

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 JeffHardddyyy · Nov 27, 2016 at 03:47 PM 0
Share

Okay, This works, but Is there anyway to have it so it's like a fighting{ish} style,

So after it connects with something (maybe a oncollision enter), it resets?

Sorry I am only like one month(ish) new to Unity

avatar image OneEyeMaker JeffHardddyyy · Nov 27, 2016 at 04:21 PM 0
Share

I can't say, what you should do, because I don't know, what you want to do. In one case you need specific Physical material with bounciness, in another - you need apply gravity on Rigidbody component. Or, maybe, you need special OnCollision...() method. It depends on what you want to do. In any case - RTF$$anonymous$$ :)

avatar image JeffHardddyyy OneEyeMaker · Nov 27, 2016 at 05:27 PM 0
Share

I just want it so : It goes up while rotating like a normal kick,

Then when it connects with something with the tag of "Enemy" or something, it resets its position.

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

71 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

Related Questions

Helicopter Move Local Position,Local Position 1 Answer

Are I stupid? Vector3 1 Answer

Gameobjects transform position minus range 1 Answer

Object to walk forward, turn 180 and walk back 1 Answer

Instantiating gameobject creates it at second impact point 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