• 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 PrinceNikos13 · Jun 12, 2017 at 08:59 AM · transform.positionaxisglobaly-axis

How can I move an object based on a global axis?

Hello,

I 'm trying to make a flying- beetle game and I want my bugs to fall towards the ground when the die but I can't think/find out how to move them on global axis. I use accelerator input from android so my Y-Axis change on my player. So when it dies, it goes up or left / right. It's a pretty funny glitch to watch but ruins the reality of the game.

Any ideas on how to fix it?

Thanks In advance!!! : )

     void FixedUpdate()
     {
         if (currentHealth <= 0 &&  isDead == false)
         {
             isDead = true;
             BeetleAudio.PlayOneShot(BeetleDieing);
         }
 
             if (isDead)
                   Death();
     }    
     void Death()
     {
         anim.SetTrigger("Die");
         playerRB.isKinematic = true;
         fly_Movement.enabled = false;
         transform.Rotate(new Vector3(0, 0, 0) * Time.deltaTime);
 
         if (transform.position.y >0)                                        //Check if above ground before and while sink
         transform.Translate(new Vector3 (0, -fallingSpeed, 0) * Time.deltaTime);
         else
         transform.Translate(new Vector3(0, 0, 0));
       }
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 Garazbolg · Jun 12, 2017 at 11:30 AM

By delfault the Tranform.Translate method use local space. But there is a second optional parameter that allows you to choose the space like this :

 transform.Translate(new Vector3 (0, -fallingSpeed, 0) * Time.deltaTime ,Space.World);

Comment
Add comment · Show 6 · 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 rugvedkhandekar · Mar 25, 2018 at 05:45 PM 0
Share

What is the 'space.World' ??? Actually, I want to move an NPC in Global axes while rotating them in Local axes. How do I do that??? I tried this..

transform.Translate(new Vector3 (speed*Time.deltaTime, 0 , 0);

It doesn't work. Can you Help me? Thanks in advance.

avatar image NoMoneys rugvedkhandekar · Mar 25, 2018 at 06:34 PM 0
Share

There is several methods for rotating an object, if you want to apply a constant rotation you should use transform.Rotate();

example:

transform.Rotate(15,0,0)

explanation:

This rotates the transform along it's local X-axis by 15 degrees every frame.

avatar image rugvedkhandekar NoMoneys · Mar 25, 2018 at 06:38 PM 0
Share

Yes, Thank You. What I actually want to do is, rotate an object on the local axes. as you mentioned, I used " transform.Rotate(0,180,0);" I also want to move it forward. But for that I cant use local axes, because the axes are constantly rotating and the object won't neatly move forward on the same local axes. Hence I want to know how to move them on the global axes. Do you know, how to move on global axes? Thanks in advance.

Show more comments
avatar image BostonGamesLLC · Oct 07, 2020 at 09:30 PM 0
Share

Thank you, this helped me as well!

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Toggle the Y axis Invert in MouseLook.cs with a keystroke? 3 Answers

Camera Movement Bounds? 1 Answer

first person controller parent move objects along y-axis 1 Answer

AddForce() in axis x and y not working 0 Answers

Rotating Player Controller locally or globally. 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