Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RFPS + Ultimate Fracturing and Destruction

Discussion in 'Scripting' started by Joseph-Townsend, Feb 1, 2015.

  1. Joseph-Townsend

    Joseph-Townsend

    Joined:
    Dec 3, 2014
    Posts:
    31
    I know how to generate an item and everything with UFD, however I can not figure out how to get raycasting to work below is what I am looking to do.

    RFPS character shoots a building > The more damage done the more it fractures
    > 100% fractured

    RFPS character hits a tree with an axe > The more damage done the more it cuts away > Tree falls down when no support is left > Tree is split into section and each section is a game object so it can be added to inventory.

    If you can help as an individual or team effort I am sure this will help far beyond myself when other try to search for the help.

    To keep this simple for others to read as well please include the script code, what script and/or game object to attach it to and if possible what line (assuming RFPS is unmodified)
     
  2. UGTools

    UGTools

    Joined:
    Oct 10, 2012
    Posts:
    738
    Hello there!

    The first and last sample scenes included with the UFD package have your typical FPS+weapon that shoots and fractures things scenario.

    We have tried to make it as simple as possible for you developers, so it will only take 2 lines of code (one to raycast, the other to perform the actual impact):

    Code (csharp):
    1.  
    2. RaycastHit hitInfo; // This contains info about our raycast hit
    3.  
    4. // Do a raycast check, we have our weapon source and the direction it is aiming at.
    5. // ChunkRaycast returns the chunk we hit, and null if we did not hit any chunk at all.
    6. FracturedChunk chunkRaycast = FracturedChunk.ChunkRaycast(v3WeaponSource, v3WeaponDirection, out hitInfo);
    7.  
    8. if(chunkRaycast)
    9. {
    10.     // We hit something! Now notify the Fracturing tool of an impact on that chunk, and let him do all
    11.     // the dirty work (sound, particles, physics, effects...)
    12.     chunkRaycast.Impact(hitInfo.point, ExplosionForce, ExplosionRadius, true);
    13. }
    14.  
    So basically you just need your weapon source and aim direction and that's it :)