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 ZizoMass · Nov 24, 2020 at 06:28 PM · movementrigidbody2danglebulletbounce

Bounce into the air

0

Hi guys

I'm working on a 2D game, and I need a projectile prefab bounce/flap/jump in the middle of the air after the player press the mouse. In this case, while it moves along the X-axis, it is necessary to apply a force inversely proportional to the projectile's angular direction on the Y-axis in relation to its own x-axis line (only when it has a negative angle in relation to the horizontal line). The new velocity should be minimally lower than the previous one, divided by the percentage of "SlowDownFactor." Something like that: alt text

I'm new to Unity, so I don't know exactly which commands to use to apply this inverse force, I've already taken a good look at the documentation, but I haven't been very successful. The code I have so far:

 {
     [Range( 0, 1 )]
     public float SlowDownFactor = 1;
     private Rigidbody2D red_rigidbody;
 
 
     public void ExecuteAirSpecial()
     {
         red_rigidbody = GetComponent<Rigidbody2D>();
         Vector3 redAng;
         red_rigidbody.AddRelativeForce(Vector3.Angle(redAng.y, -redAng.y) * SlowDownFactor);
     }
 }

captura-de-tela-2020-11-21-023556.jpg (55.2 kB)
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 Envans · Nov 24, 2020 at 06:35 PM

 [Range( 0, 1 )]
      public float SlowDownFactor = 1;
      private Rigidbody2D red_rigidbody;
  
  
      public void ExecuteAirSpecial()
      {
          red_rigidbody = GetComponent<Rigidbody2D>();
     
          red_rigidbody.AddRelativeForce(Vector2.Perpedicular(transform.forward) * SlowDownFactor);
      }

try this, it adds a force to the direction perpdicular to the objects forward (normal in your image)

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 ZizoMass · Nov 25, 2020 at 05:47 PM 1
Share

Hi there, thanks for your awsare. I end up going like that:

 public class AirSpecialBounce : $$anonymous$$onoBehaviour, IAirSpecial
 {
     [Range( 0, 1 )]
     public float SlowDownFactor = 1;
     private Rigidbody2D red_rigidbody;
 
 
     public void ExecuteAirSpecial()
     {
         red_rigidbody = GetComponent<Rigidbody2D>();
         Vector2 red_velocity = red_rigidbody.velocity;
         if (red_velocity.y < 0)
         {
             red_rigidbody.AddForce(new Vector2(0, -red_velocity.y) / (SlowDownFactor / 100));
         }
     }
 }

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

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

Determining the angle of a projectile collision. 2 Answers

Bullet Behavior with bounce without loosing speed when bounce with another objects. 1 Answer

problem with 2d movement down slopes 0 Answers

Disabling diagonal movement in Unity 5 2D? (using C#) 1 Answer

How to make cars rotate towards a waypoint while turning? 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