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 Sokco816 · Jun 13, 2012 at 09:10 AM · rigidbodyvelocitydirection

velocity direction and reversing it

hey guys, i'm in the middle of making a snowboarding game where I want the velocity of the snowboard to be in the direction it is facing. The way I'm trying to do this is by saying "if the velocity direction is not the snowboard direction, then add a force in the opposite direction of the velocity to counter it". This is what I have so far(but it's not working):

 if(rigidbody.velocity.normalized != transform.eulerAngles){
 var velocityDirection = transform.InverseTransformDirection(rigidbody.velocity.normalized.x, rigidbody.velocity.normalized.y, rigidbody.velocity.normalized.z);
 rigidbody.AddForce(velocityDirection * rigidbody.velocity.magnitude);}

I would appreciate it if you guys could help me out with this one. Thanks!

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 hijinxbassist · Jun 13, 2012 at 09:13 AM 0
Share

Seems like using hills and a rigidbody would be a simple solution to avoid coding things like this. Seeing how snowboarding is all physics driven, why not let the physX engine take care of it?

avatar image whydoidoit · Jun 13, 2012 at 09:17 AM 0
Share

Guess he wants the effective friction and board shape to be like a boats keel and convert the lateral movement into forwards movement.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Jun 13, 2012 at 09:16 AM

How about:

   void FixedUpdate()
   {
         rigidbody.velocity = transform.forward * rigidbody.velocity.magnitude;
   }
Comment
Add comment · Show 10 · 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 Sokco816 · Jun 13, 2012 at 10:17 PM 0
Share

Thanks $$anonymous$$ike! That works, but it seems to be a little sensitive. For example, my "forward" is supposed to rotate 180 when the board flips direction. So when I play the game, I get immediate changes of direction when I start to ride switch(when my back foot is in front of my front foot). Is there any way to make it any less sensitive?

alt text

avatar image whydoidoit · Jun 13, 2012 at 10:19 PM 0
Share

Hey mate - sorry your "answer" was in moderation - btw on Unity Answers you should use "Add New Comment" for this kind of thing as it isn't a "solution". There's a link hidden on the right and comments don't need moderation.

avatar image whydoidoit · Jun 13, 2012 at 10:19 PM 0
Share

And yep - there is:

avatar image whydoidoit · Jun 13, 2012 at 10:21 PM 0
Share

To make this happen over time you could do this:

    rigidbody.velocity = Vector3.Lerp( rigidbody.velocity, transform.forward * rigidbody.velocity.magnitude, Time.deltaTime / 1); //Change /1 to fit your preferred speed of change, the bigger it is the slower
avatar image Wolfram · Jun 14, 2012 at 12:33 PM 2
Share

Huh, where did my comment go?

I was mentioning that transform.forward * rigidbody.velocity.magnitude will keep the velocity the same, even when doing extreme swerving motions. For a more realistic approach (i.e., slowing down if you turn by a large angle), use Vector3.Project(rigidbody.velocity,transform.forward).

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

6 People are following this question.

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

Related Questions

Rigidbody Local Velocity 1 Answer

How to move rigidbody object towards a target object 0 Answers

How to use local angular velocity? 1 Answer

NSEW Direction of Rigidbody Velocity 3 Answers

Getting Turret to Fire on the Correct Top-Down Plane 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