Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 DEGUEKAS · Mar 19, 2020 at 01:53 AM · physicsrigidbodyfixedjoint

FixedJoint for wall

I'm creating a system to break the wall, one with the fragmented mesh like this

alt text

But first I'm doing unity tests with a wall made of cubes.


1.the Script is assigned the rigidbody of the fragments that it has around it creates a FixedJoint and assigns the rigidbody and when I have fired and ends the fragment life eliminates the FixedJoint that it has with the surrounding blocks and activates rigidbody. Gravity to fall.
2.but if you stay with one you'll still be on the wall by the FixedJoint


3.my problem is when you don't have any block attached to the wall should drop the block but as they still detect the fixedJoint blocks that are also not attached to the wall does not fall, I do not know what is the best way to do it alt text

This is the code that handles everything


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class WallSystem : MonoBehaviour, IHurt
 {
     [SerializeField]
     private Rigidbody[] _RigidFixed;
     private Rigidbody _rigid;
 
     public FixedJoint[] fixeds;
 
     [Space(10)]
     [SerializeField]
     private int lifeBlock = 2, speed;
     private int i = 0;
 
     public bool canInput;
 
     private void Start()
     {
         fixeds = new FixedJoint[_RigidFixed.Length];
         _rigid = GetComponent<Rigidbody>();
 
 
         foreach (Rigidbody rigid in _RigidFixed)
         {
             FixedJoint fixeJoint = gameObject.AddComponent<FixedJoint>();
             fixeJoint.connectedBody = rigid;
             fixeds[i] = fixeJoint;
             i++;
         }
     }
 
     #region DestroyFixedJoint
     public void Damage(int damage)
     {
         lifeBlock -= damage;
 
         if (lifeBlock <= 0)
         {
             StartCoroutine(EliminateFixedJoint());
 
             _rigid.constraints = RigidbodyConstraints.None;
             _rigid.useGravity = true;
 
            _rigid.AddRelativeForce(Random.onUnitSphere * speed);
         }
     }
 
     IEnumerator EliminateFixedJoint()
     {
 
         while (true)
         {
             if (gameObject.GetComponent<FixedJoint>() == null)
                 break;
 
             destroyThisFixedJointInOther();
 
             FixedJoint fixedJoint = GetComponent<FixedJoint>();
             Destroy(fixedJoint);
 
             yield return null;
         }
     }
 
     void destroyThisFixedJointInOther()
     {
         foreach (Rigidbody g in _RigidFixed)
         {
             WallSystem wallSystem = g.transform.gameObject.GetComponent<WallSystem>();
 
             foreach (FixedJoint fixedJ in wallSystem.fixeds)
             {
 
                 if (fixedJ != null && fixedJ.connectedBody.name == this.name)
                 {
                     Destroy(fixedJ);
                 }
             }
         }
     }
     #endregion
 
     //En teoria si no se conecta con la pared deberia caer
     //In theory if you don't connect to the wall you should fall
     private void Update()
     {
         foreach (FixedJoint fixedJ in fixeds)
         {
             if (fixedJ == null)
                 Destroy(fixedJ);
         }
 
         if (GetComponent<FixedJoint>() == null)
         {
             _rigid.constraints = RigidbodyConstraints.None;
             _rigid.useGravity = true;
         }
     }
 }
 


I'd like it to be like this wall that when it doesn't connect to the wall the block falls

alt text

captura1.png (474.6 kB)
photo-2020-03-18-11-19-20.jpg (57.9 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

229 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Missiles attached with FixedJoint cause too much torque for airplane physics 1 Answer

Fixed joints are weak 4 Answers

Preventing a grenade from colliding with its thrower 2 Answers

Changing the speed and accelleration of a jump using the built-in Physics Rigidbody engine in Unity? 0 Answers

Stopping animation affecting physics 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