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 Gamelands-Studio · Aug 11, 2019 at 05:05 PM · collisionrigidbody2dexplosion

Objects moving weird after collision with other objects - rigidbody2d

i have a bear in my game, and i have an alien that explodes, the bear moves using Vector2.MoveTowards, and has rigidbody2d on it, when the alien explodes, it does (AddForce) effect on the objects around, however my bear starts moving weird and rotates weird too :( pls help alt text

after explosion: alt text

1.jpg (8.9 kB)
2.jpg (10.0 kB)
Comment
Add comment · Show 13
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 sacredgeometry · Aug 11, 2019 at 05:50 PM 0
Share

Because it is one of the objects around it?

Please post the relevant code.

avatar image Gamelands-Studio sacredgeometry · Aug 11, 2019 at 06:43 PM 0
Share

it's just rigidbody, the bear moves around using vector2.$$anonymous$$oveTowards(), and has a rigidbody to detect collisions, the other monster explodes, and when he explodes he has that explosion effect to push objects away, and i used Rigidbody.addForce(), but because of the rigidbody attached to the bear, he moves using $$anonymous$$oveTowards but at the same time has force on it and that force stays a bit long and creates a weird movement for the bear, (he moves like an object in space) is there any way to make that effect not take that long, maybe something with forcemode or something pls help :(

avatar image sacredgeometry Gamelands-Studio · Aug 11, 2019 at 06:46 PM 0
Share

No ones going to be able to debug your code for you without having access to the code.

avatar image Gamelands-Studio · Aug 11, 2019 at 07:05 PM 0
Share

this is the code that generates the explosion

   void checkDistance()
         {
             if (player != null)
             {
                 if (Vector2.Distance(transform.position, player.position) <= 1.75f)
                 {
     
                     Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, radius);
     
                     foreach(Collider2D collider in colliders)
                     {
                         Rigidbody2D rb = collider.GetComponent<Rigidbody2D>();
                         if(rb != null)
                         {
                             RigidbodyExplosion.AddExplosionForce(rb, explosionForce, transform.position, radius);
                         }
                     }
     
                     GameObject instance = SpawnObject.WithRotation(WormSplashEffect, transform);
                     Destroy(instance, 1f);
                     Destroy(gameObject);
                 }
             }
         }
 

and this the code for the explosion effect:

 using UnityEngine;
 
 public static class RigidbodyExplosion
 {
     public static void AddExplosionForce(this Rigidbody2D body, float explosionForce, Vector3 explosionPosition, float explosionRadius)
     {
         var dir = (body.transform.position - explosionPosition);
         float wearoff = 1 - (dir.magnitude / explosionRadius);
         body.AddForce(dir.normalized * explosionForce * wearoff);
     }
 
 }

avatar image Gamelands-Studio Gamelands-Studio · Aug 11, 2019 at 07:06 PM 0
Share

@sacredgeometry here

avatar image sacredgeometry Gamelands-Studio · Aug 11, 2019 at 07:07 PM 0
Share

Can you move it into a comment ins$$anonymous$$d of an answer please. Or onto the original question ideally.

Show more comments
Show more comments

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

163 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

Related Questions

Rigidbody2D.velocity out of controll 3 Answers

IsTrigger Effecting collision 1 Answer

How to go about having two seperate Game Objects follow eachother? 1 Answer

Error when colliding and calling a IEnumerator 1 Answer

Issue with adding force and lerping position? Possible unity bug? 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