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 andreighinea1 · Jul 09, 2017 at 04:32 PM · movementtransformvelocityphysics2dtutorial

Up Velocity

I watched this tutorial: https://www.youtube.com/watch?v=0Quv9U9_a8c about making a racing game in unity, but I didn't understand why the ForwardVelocity() function was returning only the up velocity.

From 32:40 he starts explaining what he wants to do, and how.

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
0

Answer by Major · Jul 09, 2017 at 05:00 PM

The two functions, ForwardVelocity () and RightVelocity (), return the individual components of the car's velocity vector. He does this so that he can more easily manipulate them individually.

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 andreighinea1 · Jul 12, 2017 at 05:02 AM 0
Share

Why did he use the dot product? Couldn't he just do this :

rb.velocity = new vector2(rb.velocity.x*0.9,rb.velocity.y);

Because he wanted to kill 10% of the right velocity.

avatar image andreighinea1 · Jul 15, 2017 at 03:57 PM 0
Share

@$$anonymous$$ajor
So ? Wouldn't it be the same ?

avatar image Major andreighinea1 · Jul 15, 2017 at 05:36 PM 1
Share

@andreighinea1 I am so sorry about the delayed reply, I didn't get an email... Damn forums...

What quill was doing was returning the world space conversion of the local forward and right vectors. In essence the equivalent of doing:

 Vector3 forwardVec = transform.TransformVector (transform.forward);

and

 Vector3 rightVec = transform.TransformVector (transform.right);

While his method of using dot is valid, as you can see it's more complicated and he didn't explain it.. well, at all.

Your method is exactly the same, given you convert the local forward, and right vectors to world space before you did your operations.

Again, sorry about the lateness of this, I hope that helps you understand his code a little better.

avatar image andreighinea1 Major · Jul 16, 2017 at 06:55 AM 0
Share

@$$anonymous$$ajor
Thanks! Now I understand why he had to do the dot product of the velocity of the player and the world up axis ... Just to convert the local player axis to the world axis.

But when I try to do like you said it doesn't really work:

{...
rb.velocity = UpVelocity () + RightVelocity () * 0.9f;
}
Vector2 UpVelocity(){
    return transform.TransformVector (transform.up);
}
Vector2 RightVelocity(){
    return transform.TransformVector (transform.right);
}
The x velocity of the car is always around 0.9 and the y velocity is around 1. That's because the transform.up is in world space and it's always 1, same for the right one.

Show more comments

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

107 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

Related Questions

Choosing speed and direction of AddForce 1 Answer

Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer

Unity network transform massive movement jitter jumps 0 Answers

Have object fly towards camera 0 Answers

Movement in the direction the user is facing with arrow keys 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