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 robertofantasy · Aug 14, 2012 at 12:05 PM · rotate

translate method dont work with rotate method

here is my question when i want rotate my object contniously the translate method not work

i mean my object never translate and in addition this two method not work with each other

what ican di ?

 using UnityEngine;
 using System.Collections;
 
 public class Enemy : MonoBehaviour {
      public float EnemySpeed;
      // Use this for initialization
      void Start () {
 
          gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, 28);
  
      }
  
      // Update is called once per frame
      void Update () 
      {
          gameObject.transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed);
 
          gameObject.transform.Rotate(Vector3.up * 30);
 
          if (gameObject.transform.position.z < -88)
          {
              Destroy(gameObject);
          }
         //gameObject.transform.Rotate(Vector3.up * 10);
  
      }
      void OnTriggerEnter(Collider colide)
      {
          Destroy(gameObject);
      }
 }


 
Comment
Add comment · Show 2
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 Kryptos · Aug 14, 2012 at 12:33 PM 1
Share

Formatted the code for you.

avatar image robertofantasy · Aug 14, 2012 at 01:16 PM 0
Share

thanks for formatting learn how to do that but what about my question

1 Reply

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

Answer by Kryptos · Aug 14, 2012 at 01:30 PM

Not sure to understand what you are trying to achieve.

 gameObject.transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed);

This line will make your object translate relatively to its local left vector. But since it also rotates each frame around the local y-axis, the translation direction will always be different. Therefore it looks like the translation never occured.

If you want to translate on the same direction (here Vector3.left), you should use this code instead:

 transform.Translate(Vector3.left * Time.deltaTime * EnemySpeed, Space.World);

Now, the rotation does not use the framerate which is not consistent. Consider using this code instead:

 transform.Rotate(Vector3.up * Time.deltaTime * 30, Space.Self);

This will make your object rotate by 30 degrees per second around the local y-axis. Note that Space.Self is a default value, but it is better to set it explictly so that mistakes can be avoided.

Comment
Add comment · Show 2 · 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 robertofantasy · Aug 14, 2012 at 01:44 PM 0
Share

my friend you are god that is best explain that ever i hear

so the default in transform is local is that right ?

so if i have question how can directly ask you ?

avatar image Kryptos · Aug 14, 2012 at 03:09 PM 0
Share

@robertofantasy the default is these two particular methods is local. You can find that information in the documentation.

You cannot ask me directly: the purpose of this website is to be a knowledge database. Everyone can learn from other errors/mistakes/issues.

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

9 People are following this question.

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

Related Questions

Camera rotation around player while following. 6 Answers

Doesn't Add Rotation Over 180 2 Answers

Double axis rotation mixing. 1 Answer

Lock Z Rotation. Character Controller. 1 Answer

how do I make a joint that fixates the objects distance but lets them rotate freely? 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