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
-1
Question by Creative Inventory · Nov 14, 2015 at 06:28 PM · 2dforcemode

ForceMode2D.Impulse problem

How do I stop my player from getting dragged back after collision?

   void OnTriggerEnter2D(Collider2D other)
    {
    if (other.tag == "Bouncy object")
      GetComponent<Rigidbody2D>().AddForce(transform.right * 15, ForceMode2D.Impulse);
    }
Comment
Add comment · Show 2
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 Statement · Nov 14, 2015 at 06:38 PM 0
Share

Please explain what you mean by "getting dragged back after collision". What is "dragged back"?

avatar image Creative Inventory Statement · Nov 14, 2015 at 06:58 PM 0
Share

like it's being pulled back by a magnet! Which I don't want, I just want my player to get push back by a tagged object and stays there

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by davidgab98 · Mar 31, 2020 at 08:38 PM

     // You can set its velocity as zero:
     void OnTriggerEnter2D(Collider2D other)
         {
         if (other.tag == "Bouncy object")
           GetComponent<Rigidbody2D>().velocity = Vector2.zero;
         }
     
     // Also you can change to true the variable isKinematic from player RigidBody2D:
     void OnTriggerEnter2D(Collider2D other)
         {
         if (other.tag == "Bouncy object")
           GetComponent<Rigidbody2D>().isKinematic = true;
         }
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
avatar image
0

Answer by streeetwalker · Mar 30, 2020 at 03:48 PM

@Creative Inventory , I'm not sure why you're downvoted for your question, but you don't provide enough of your code to tell what is going on.

For sure you code works as it is written. When your objects touch each other, a force of 15 is applied to the positive x direction.

So if that is not what you want to have happen, you must have other forces that act on the object, or you are trying to position the object in some other way (like setting the transform.position - which you should not do if you are using the rigidbody physics engine.)

So we can't tell what you are trying to do in the code. You want this to act as a booster for the player? Or you want the player collide and bounce off some object?

if you want the player to bounce off, you should probably not use a trigger collider to do that - just turn off the trigger and let the object collide and bounce off.

You have to explain how things are expected to work in detail. What objects are involved, what the set up is, and what is the rest of the code!

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

48 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

Related Questions

Instantiate 2D gameobject with force towards Z-Direction 0 Answers

Jump Force/Velocity is Wrong and Strange. Help 1 Answer

[2D] Velocity increases faster after large force is applied. 0 Answers

Throw Rigibody2D cannon to a 2D target (with gravity), reach in time, how to calculate Addforce ? Please & Thx 0 Answers

Gradually rotate to slope angle 3 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