Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Cloky · May 26, 2020 at 01:58 PM · unity 2drigidbody2daddforceforcedrag

Use Rigidbody2D's Drag to slow down flying character

I have a character that gets launched into the air with rb.AddForce(direction * punch_strength_value * punch_strength_total);

I want this character to be slowed down the higher he is in the air, creating a "soft-limit" so the character does not go too far up. I figured this could be done by changing the Rigidbodies drag according to the character's height, but I was wrong:

 public float height_slowdown = 1;
 void Update()
     {
         heigth = transform.position.y;
         rb.drag = height * height_slowdown;
     }

Using this, the character launches into the air and is then slowed down very abruptly as if there was an invisible wall (meaning the X value does not change anymore). He then falls very slowly to the ground.

The character starts at X:0 Y:0 if that's of any help.

How do I make the character to slow down his gain in height the higher he is?

Comment
Add comment · Show 1
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 Cloky · May 28, 2020 at 07:59 AM 0
Share

As no one seems to have an answer I tried ins$$anonymous$$d of using a higher drag, to give the rigidbody a higher mass. Weirdly, after adding force to the rigidbody, the rb does not care about its mass anymore. Can someone explain?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CiberX15 · Mar 25, 2021 at 03:58 AM

Sounds like your problem is mostly coming from applying drag in all directions. Below are a few ways to apply a drag-like effect exclusively on the Y-axis of the velocity.

 //This method removes a percentage of the velocity every frame and gets closer to zeroing that velocity the closer to max_height it gets.
 float max_height = 100;
 private void Update()
 {
     height = transform.position.y;
     float reduceSpeadPercentage = height / max_height;
 
     Vector3 velocity = rb.velocity;
     velocity.y -= velocity.y * reduceSpeadPercentage;
     rb.velocity = velocity;
 }
 
 //This method applies an increasingly powerful downward force the higher you go. Which will make objects flung up higher, fall down faster.
 public float height_slowdown = 0.1f;
 void Update()
 {
     height = transform.position.y;
     float reduceSpeadPercentage = height / max_height;
 
     Vector3 velocity = rb.velocity;
     velocity.y -= height * height_slowdown;
     rb.velocity = velocity;
 }
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

139 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 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

Physics are different in Build and Editor 0 Answers

Adding force to rigidbody2d to slide 1 Answer

How to set rigidbody force 1 Answer

Acceleration and Max Speed on 2D Object 0 Answers

Add a force at an angle 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