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 /
  • Help Room /
avatar image
0
Question by fantafairy74 · Jul 26, 2018 at 03:26 PM · unity 2dhovering

RigidBody2D Hovering not working some computer

Hello i make 2D Game and implemented hover effect(floating).

first my rigidbody2D component option is blew picture.

alt text

and I made the hover function work by pressing and holding the X button.

Below is the source I created.

 void Update()
 {
     CheckJump();
     CheckRavitate();

     DoingAction();
 }

 void DoingAction()
 {
      if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.JUMP))
      {
          // Jump
          this.rigid2D.AddForce(transform.up * JUMP_FORCE);
          nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.JUMP;
      }

      if (IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE))
      {
          RaycastHit2D rayHitData = Physics2D.Raycast(
                  new Vector2(transform.position.x, transform.position.y),
                  new Vector2(0, -1.0f),0.5f,
                  1 << GlobalLayerMask.TERRIAN_MASK);
          bool canRavitate = rayHitData.collider ? false : true;
          Debug.DrawRay(transform.position, new Vector2(0, -0.8f),Color.green);
          if (canRavitate)
          {
              float yVel = Physics.gravity.y;
              Debug.Log("Ravitae FORECE " + yVel);

              //Howering
              rigid2D.AddForce(new Vector2(0, -yVel), ForceMode2D.Force);
          }
      }
 }

 /*
 My intention is that when the x key is pressed for more than 0.05 seconds, 
 the floating flag is turned on.
 When you release x, it will be off.
 */
 void CheckRavitate()
 {
     if (true)
     {
         if (Input.GetKey(KeyCode.X))
         {
             if (raviValue.canRavitate && Time.time - raviValue.tDown > 0.05f && rigid2D.velocity.y < 0.2f)
             {
                 Debug.Log("RAVITATE FLAG ON");
                 nowStatus |= CustomCharacterInfo.CHAR_STATUS.RAVITATE;
                 rigid2D.velocity = new Vector2(0.0f, 0.0f);
                 raviValue.canRavitate = false;
             }
         }

         if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE) && Input.GetKeyUp(KeyCode.X))
         {
             nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.RAVITATE;
             raviValue.canRavitate = true;
         }
     }
 }



 void CheckJump()
 {

     // Jump Function
     if (Input.GetKeyDown(KeyCode.X) && jumpcount > 0)
     {
         isGrounded = false;
         nowStatus |= CustomCharacterInfo.CHAR_STATUS.JUMP;
         jumpcount--;
         raviValue.tDown = Time.time;
     }
 }
 
 public class RavitateFlag
 {
     public float tDown;
     public bool canRavitate;
     public RavitateFlag()
     {
         tDown = Time.time;
         canRavitate = true;
     }
 }

that result below that

alt text
that was errormotion capture
alt text

that was correct motion capture

The issue does not floating work with the player's computer.

I do not know why this is the difference. The code is the same and the log is the same too.

If you change one gravitiscale to 1, floating function works normally.

But I think that this is not a solution. Also, when you change the gravity scale to 1, the character that was in normal operation will fly to the sky.

I guess it is time to call the update function, but this is also not clear.

rigidbody2d.png (17.4 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

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

152 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

Related Questions

Convert Keyboard controlls to UI Buttons 1 Answer

(2D Top Down Shooter, Unity2D) Creating a bullet trail effect? 0 Answers

Player Skins Won't Load 0 Answers

How to store max y position of object 0 Answers

unity2d One Scene Not Working 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