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 ARRAYEWHY · Jan 27, 2014 at 03:40 PM · collisionaddforceoncollisionenter

AddForce not working on Rigidbody2D.

I have a floating island that Translates up and down with a Rigidbody2D (Gravity Scale = 0). I'm trying to AddForce it upwards when the Player lands on it but it just floats down with the character. I've tried disabling the 'floating' but AddForce still won't kick in. Debug.Log shows Player entering the collider.

 bool goUp = false;
 
     void Update ()
     {
         if (goUp == true)
             driftUp ();
         else if (goUp == false)
             driftDown ();
     }
 
     void driftUp ()
     {
         transform.Translate (Vector2.up * .05f * Time.deltaTime);
 
         if (transform.position.y > -.9f)
             goUp = false;
     }
 
     void driftDown ()
     {
         transform.Translate (-Vector2.up * .05f * Time.deltaTime);
 
         if (transform.position.y < -2)
             goUp = true;
     }
 
     void OnCollisionEnter2D (Collision2D contact)
     {
         if (contact.gameObject.tag == "Player")
             rigidbody2D.AddForce (Vector2.up * 100f * Time.deltaTime);
     }
Comment
Add comment · Show 4
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 Flint Silver · Jan 27, 2014 at 03:53 PM 0
Share

have you tryed to add Gravity Scale ? And to addForce up at the island to keep it flying?

avatar image ARRAYEWHY · Jan 27, 2014 at 04:23 PM 0
Share

Yea, I returned Gravity Scale to 1 (Physics2D, -30), Disabled "driftUp/Down", and added a simple AddForce with Vector.Up to keep it in place. Player jumped on it, and still no extra force.

avatar image sanitarioom · Jan 27, 2014 at 05:53 PM 0
Share

Try to add new empty game object attached to player, positioned under his position (not much). Floating islands need to have layer mask, ie. called "islands" or what you want. Then check if player stands on "island" with this code:

`Physics2D.Linecast(transform.position, groundCheck.transform.position, 1 << Layer$$anonymous$$ask.NameToLayer("islands"));`

where groundCheck is your new empty object. Then just add a condition if player stands on floating island and add force. I had the same problem when I had checked Apply root motion. Gravity scale and mass set to 1.

avatar image ARRAYEWHY · Jan 28, 2014 at 12:49 AM 0
Share

Strangely enough, it was the Time.deltaTime on line 30 breaking things. I removed it and now my Player bounces on the island as though it were a trampoline.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ARRAYEWHY · Jan 28, 2014 at 12:49 AM

Remove Time.deltaTime.

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

20 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

Related Questions

Rigidbody not calling OnCollisionEnter 1 Answer

KnockBack Effect. 1 Answer

On Trigger Enter, Collide with object, specific collision 1 Answer

Collision Only being detected on one of the objects involved in the collision - C# 0 Answers

Colliding two GameObjects 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