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 LieTR · Jan 30, 2014 at 05:49 PM · physicsvelocityaddrelativeforceice

slowing sideways velocity

I'm making a snowboarding game. When the user presses the "w" key, I speed up the snowboarder using this:

 if (Input.GetKey(upKey)){
     rigidbody.AddRelativeForce(new Vector3(0,0,1)*1000f);
 }

When I turn the character, all that relative forwards velocity has now become sideways velocity. I assume that I need to apply some variant of this code in fixedUpdate over time:

 rigidbody.AddRelativeForce(new Vector3(sideWaysVelocity,0,0)*magnitude);
 

where the magnitude variable diminishes over a short period of time (snowboarding game, a bit of drift is desired).

My questions are:

  1. Is my assumption for the solution correct?

2.)how would I calculate relative sideways velocity to give me a float between -1 & 1?

It's my first attempt at making a game, be gentle!

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 LieTR · Jan 30, 2014 at 06:36 PM

Lol! I had to type it all out to understand the problem. I just got this to work for me:

 var xVelocity : float = transform.InverseTransformDirection(rigidbody.velocity).x;
     if (xVelocity != 0){
         if (!airBorne){
             rigidbody.AddRelativeForce(new Vector3(xVelocity,0,0)* -magnitude);
         }
     }

where the magnitude variable does NOT change and rather the xVelocity does!

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 FreeTimeDev · Jan 30, 2014 at 06:45 PM

If you turn the character his forward facing direction changes as well. In your first code you apply force in the Vector3.forward direction--that direction changes with your character if you rotate him.

The easiest way to get the movement you want (IMO, maybe one of the pros will have a better Idea) is to not turn him (but use the animations you want..) and also apply a force for the sideWaysVelocity. It's about the illusion of turning and movement.

1) For your proposed solution, I think you'll eventually implement a system where your forward velocity is modified by the length of time you've been going down hill ("speeding up") and if your turning hard (Carving? To slow you down some). You'll limit the gains on magnitude use Mathf.Clamp.

2) Input.GetAxis can return -1 or 1. Multiply that and your variable for force.

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

19 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

Related Questions

How to simulate AddForce? 1 Answer

NullReferenceException: UnityEngine.Rigidbody2D.get_velocity() 0 Answers

Physics in 2d arkanoid. Tangential and normal velocity 1 Answer

Finding Velocity at point but locally.... 1 Answer

is there a way to check the path of a RigidBody.velocity? 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