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 006 · Dec 30, 2013 at 09:48 PM · transformvector3translate

transform.Translate tutorial question

I was "playing" around with this tutorial: http://unity3d.com/learn/tutorials/modules/beginner/scripting/translate-and-rotate

I ended up with this code:

 using UnityEngine;
 using System.Collections;
 
 public class TranformUp : MonoBehaviour {
 
     public int velocity = 10;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetKeyDown (KeyCode.UpArrow) || Input.GetKeyDown (KeyCode.W))
             transform.Translate(new Vector3(0 , 5 ,0) * velocity * Time.deltaTime);
         if (Input.GetKeyDown (KeyCode.DownArrow) || Input.GetKeyDown (KeyCode.S))
             transform.Translate (new Vector3(0 ,-5, 0) * velocity * Time.deltaTime);
         if (Input.GetKeyDown (KeyCode.LeftArrow) || Input.GetKeyDown (KeyCode.A))
             transform.Translate (new Vector3(-5, 0, 0) * velocity * Time.deltaTime);
         if (Input.GetKeyDown (KeyCode.RightArrow) || Input.GetKeyDown (KeyCode.D))
             transform.Translate (new Vector3(5, 0, 0) * velocity * Time.deltaTime);
     }
 }

What I don't understand is, that whatever value the variable velocity has, the result is the same.Isn't it supposed to multiply with the vector3 values?

EDIT: Even setting it to 0 doesn't change something

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
0

Answer by HuskyPanda213 · Dec 30, 2013 at 09:54 PM

The value is aslways the same because you go to a new vector 0,5,0 I would use vector3.forward or so. Then multiply.

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 · Dec 30, 2013 at 09:59 PM

velocity is basically the speed at which it moves

the vector(0,5,0) etc is, well actually its part of the overall true velocity

a velocity is a speed in meters per second FOR EACH AXIS

so a velocity of (0,5,0) is a speed of 5 meters per second in the up direction

then you multiply this by your speed which is 10 and you get

0 10; 5 10; 0 * 10

and you end up with (0,50,0) which is confusing, its actually confusing because you shouldnt use 5 there in all those new vectors you should use 1, or actually you should use the objects local left, right, up and down

this would be a properly coded example

 if (Input.GetKeyDown (KeyCode.RightArrow) || Input.GetKeyDown (KeyCode.D))
 transform.Translate (transform.right * velocity * Time.deltaTime);

this will now take transform.right, transform.right is a direction, its a point exactly 1 unit to the right of the object.

so if its 1 unit away then when we multiply by 10 for example we get a unit 10 meters away and thats what we do for speed

so if we have it at 1 unit away and leave it and it takes 10 seconds to complete we go 10% along the line each time and travel at 1/10th meter per second

if we have it 10 units away so (transform.right 10 time.deltatime) it still takes 10 seconds to comlpete the journey but 10% along this line is further away so it travels faster it goes 1 meter per second.

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

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

20 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

Related Questions

UnityEngine.Component:get_transform() Error 1 Answer

Different between transform.Translate() and Vector3.MoveTowards? 1 Answer

Move child objects in the opposite direction of parent object 0 Answers

How the player can translate 1 "unit" and not smouthly. 2 Answers

Move GameObject along a line according to the players look direction 3 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