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 egonspengler_84 · Apr 21, 2021 at 08:05 AM · transform.translate

Beginners question about transform.Translate and float values

Hi there,

I have a game object in my scene that I want to travel to the right using the transform.Translate function.

My understanding is that you put float values into the x, y and z parameters of the function in order to make a game object travel a certain distance on the x, y and z axis every frame?

So if I wrote the following in the Update function of a script that is attached to the game object:

 void Update(){
 
    transform.Translate(1f,0,0);
 
 }



Does that mean the game object will travel a distance of 1 float per frame on the X-axis? I believe Unity projects run at a 60fps frame rate so that would mean that the GO would travel 60 floats to the right per second? But what does travelling 1 float actually mean? Does each square that can be seen in the grid in the scene view represent a float value?

Any help would be appreciated.

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
1

Answer by xxmariofer · Apr 21, 2021 at 08:27 AM

Hello,

forget about the "1 float", float is a type, a type use for numbers. data types are not that simple, and you should take a look into c# basics, but think of floats as numbers with decimals.

Second, in unity games dont run at 60fps, they could be running at a higher frame rate, but it is common to cap the fps to 60 (not allways and not necesary)

Third, unity doesnt use "meters" they use "units", if you use

 transform.Translate(1,0,0);

you move in the x axis 1 unit.

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 egonspengler_84 · Apr 21, 2021 at 08:46 AM 0
Share

I understand datatypes to an extent. I understand that the int datatype is used for integer values and that the float datatype is used for decimal values.

So when using the transform.Translate function I can make a game object travel a distance measured in units? Am I right in saying that these units are represented by the small squares that are shown in the scene view in the editor as you can see in this screenshot?: https://ibb.co/5LdmRFM

Also is there a way in which I can find out how many realtime fps my project is running during runtime?

avatar image xxmariofer egonspengler_84 · Apr 21, 2021 at 09:21 AM 0
Share

Yes, the default grid every square is a unit.

You can find the time between frames with

 Time.deltaTime

this returns the value from the last frame to current frame, so if you want the movement to be frameindependant you could do

 transform.Translate(1 * Time.deltaTime,0,0);

this will move the robot 1 unit per second, instead of 1 unit per frame.

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

116 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 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

Move an object without Character Controller? 1 Answer

Vector3.Lerp with Translate Javascript 0 Answers

My object is translating with speed but does not stop... 1 Answer

transform.Translate code isn't working 0 Answers

move character at constant speed, and detect collisions. 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