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 SirMacJefferson · Oct 08, 2011 at 08:28 AM · rigidbodyvelocitylocalrelative

How do you directly add to velocity in a relative manner?

I'm trying to make a sort of booster-style function where you're instantly forced forward and up when the function is called. Since I wanted the process to be generally abrupt and not gradual, I didn't want to use rigidbody.AddRelativeForce, but I can't seem to figure out how to directly add to velocity in a way that affects it locally/relatively. I want it to force me forward based on my rotation, not along the world's Z axis.

There have been a lot of questions about relative velocity, and the answer seems to be "use Vector3.Dot" or "use transform.InverseTransformDirection". I don't know how to add to velocity locally by using those functions, however. It seems those who were posting questions about it only wanted to get your relative velocity, not add to your relative velocity.

I would prefer using velocity over AddRelativeForce, since AddRelativeForce is gradual and very hard to accurately control.

Also, I know the documentation says not to edit velocity directly, but I don't think that applies to me, as all I really use rigidbodies for is gravity (everything else physics-related is Translate-operated) and don't ever add force/torque in situation. Of course, feel free to correct me if I'm wrong here and it really will cause some kind of glitchy, unstable physics.

Hopefully this doesn't sound too much like a "write my script" question...I just really can't figure out how to go about this.

Thanks for any help you can offer!

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
2
Best Answer

Answer by Fattie · Oct 08, 2011 at 10:57 AM

Sure, it's easy:

             // here is a very unusual case in game physics.
             // we will simply "set the velocity" of the object.
             // there are very few cases where this is appropriate
             // but in this situation it is perfectly clever and good:
             
             thingy.rigidbody.velocity =thingy.transform.forward * -5.0 ;


Just as you said: there are only a few, special, circumstances where you set the velocity directly. (You are "breaking" the physics - manipulating the fabric of reality!) In short, beginners working with 3D should never do this. Hope this is what you were after.

Comment
Add comment · Show 1 · 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 SirMacJefferson · Oct 08, 2011 at 07:58 PM 1
Share

This seems to be working great. Thanks for the help and clarification!

In case someone wants to know in the future, this is the code I use to force you forward and up by predefined variables (ForwardForce and UpwardForce):

rigidbody.velocity += ((transform.forward ForwardForce) + (transform.up UpwardForce));

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

relative velocity of rigidbody according to rotation... 1 Answer

Rigidbody move relative position ? 2 Answers

Set The Local Velocity Of A Rigidbody 2 Answers

How to use local angular velocity? 1 Answer

Setting Local Velocity Of A RigidBody 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