Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 James-Covalent-Bond · Dec 09, 2017 at 03:49 PM · physicsplayerphysics2dforceplayer movement

how to have air control after a rocket jump?

Hey I'm starting Unity and I want to make a game where the player can fire two projectiles that have enough kickback to propel the player in the opposite direction. I also want the player to be be able to walk left and right, but I also want air control. I can't set the velocity of the player's rigidbody to the axis horizontal * speed because that would make my projectiles unable to push the player horizontally. If i were to control the player in the air by adding a force in the horizontal direction, that would make my player accelerate horizontally without any limit to the amount of speed my player can gain from using the arrow keys in the air. I may instead include an explosion force instead of kickback like i have now, but I believe that is irrelevant. How does tf2, and other games, include air control while having physics? I see the soldier can make an explosion and shoots the player in the air, but the player can still have some control in the air. Here is my code:

     void Update () {
 
         //direction and speed in x axis
         lrd = Input.GetAxisRaw ("Horizontal");
         lrs = lrd * lrSpeed;
 
         //check if on ground
         onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer);
 
         //jump
         if (rb.velocity.y < 0) {
             rb.velocity += Vector2.up * Physics2D.gravity.y * fallMultiplier * Time.deltaTime;
         } else if (rb.velocity.y > 0 && !Input.GetButton ("Jump")) {
             rb.velocity += Vector2.up * Physics2D.gravity.y * lowJumpMultiplier * Time.deltaTime;
         }
         if (Input.GetButtonDown("Jump") && onGround) {
             rb.velocity +=  Vector2.up * jSpeed; 
         }
 
         //move player left right
         rb.velocity = new Vector2 (lrs, rb.velocity.y);
 
         //shoot projectiles
         if (Input.GetMouseButtonDown (0)) {
             if (currentArmIndex >= 0) {
                 shake = CameraShaker.Instance.ShakeOnce(mag,roughness,inTime,outTime);
 
                 int index = Random.Range (0, shoot.Length);
                 shootClip = shoot [index];
                 audioSource.clip = shootClip;
                 audioSource.pitch = Random.Range (0.8f, 1.2f);
                 audioSource.Play ();
 
                 arms[currentArmIndex].Launch(fireSpeed);
                 rb.AddForce (arms [currentArmIndex].normalizedDifference * armKickBack * -1);
                 currentArmIndex--;
             }
 
         }
         //reload level
         if (Input.GetKeyDown (KeyCode.O)) {
             Application.LoadLevel (0);
         }
 
     }

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 nt314p · Dec 10, 2017 at 09:38 PM 0
Share

Add a force to push the character left and right?

0 Replies

· Add your reply
  • Sort: 

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

134 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

Related Questions

Player is Speeding up in collisions 0 Answers

increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer

How to brake the player? 0 Answers

Player touch input and continuous one direction movement combination 0 Answers

Unity 2D - How to calculate weight/strain? 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