Note: For this tutorial, you should have already have an understanding of how to import Models into RE thru the Builder, as well as the creation of Prefabs. This tutorial only covers the creation of Breakable Objects “after” art has already been created and imported.
/// ----------------------------------------------- /// PRECACHING & STATIC DATA VALUES /// ----------------------------------------------- /// public static string ClassName = "BreakablePot"; private static bool HasCached = false;
/// <summary> /// MEDIA /// </summary> static private MSound StaticBreakSound = MPrecacher.PrecacheSound(ClassName, "BreakPot.wav", false); static private int[] MyParticleSystems = { MPrecacher.PrecacheActorPointer(ClassName, "PotParticles.xml"), }; static private int[] PotPieces = { MPrecacher.PrecacheActorPointer(ClassName, "PotPiece1.xml"), MPrecacher.PrecacheActorPointer(ClassName, "PotPiece2.xml"), MPrecacher.PrecacheActorPointer(ClassName, "PotPiece3.xml"), MPrecacher.PrecacheActorPointer(ClassName, "PotPiece4.xml"), MPrecacher.PrecacheActorPointer(ClassName, "PotPiece5.xml"), MPrecacher.PrecacheActorPointer(ClassName, "PotPiece6.xml") }; static private MVector[] PotPiecesOffsets = { new MVector(-0.06079591f,0.180491f,-0.138583f), new MVector(-0.05181848f,0.2195758f,0.1360596f), new MVector(0.1639841f,0.05911997f,0.08252703f), new MVector(0.01162986f,-0.2269091f,-0.01701386f), new MVector(-0.2153126f,-0.1845589f,0.07264592f), new MVector(0.1189805f,-0.3204344f,-0.1920157f) };
public BreakablePot(MWorld world) : base(world) { Precache(); Pieces = PotPieces; PiecesOffsets = PotPiecesOffsets; BreakSound = StaticBreakSound; ParticleSystems = MyParticleSystems; }
public static void Precache() { MPrecacher.Precache(ClassName, HasCached); if (!HasCached) { for (int i = 0; i < PotPieces.Length; i++) { MActor theActor = MActor.GetFromPointer(PotPieces[i]); if (theActor == null || !(theActor is NetMultiShapeActor)) continue; NetMultiShapeActor potPiece = (NetMultiShapeActor)theActor; potPiece.SpawnByName = false; } HasCached = true; } }
Note: The actual functionality for taking damage, breaking, disposing, etc are handled in BreakableObject?.cs.
Note: Anytime you use a different name or change names around, you need to make sure to edit the Constructor and the Precache function which both reference the Media variables that you have specified.
Note: There are numerous ways of doing this and feel free to work it however you want, but this is the way I like to do mine.
static private MVector[] PotPiecesOffsets = { new MVector(-0.06079591f,0.180491f,-0.138583f) };
static private MVector[] PotPiecesOffsets = { new MVector(-0.06079591f,0.180491f,-0.138583f), new MVector(-0.05181848f,0.2195758f,0.1360596f), new MVector(0.1639841f,0.05911997f,0.08252703f), new MVector(0.01162986f,-0.2269091f,-0.01701386f), new MVector(-0.2153126f,-0.1845589f,0.07264592f), new MVector(0.1189805f,-0.3204344f,-0.1920157f) };
Note: BreakableObjects have a BreakThreshold?, as well as AttachedLight? settings which can be used to attach a Light to a Breakable Object (Hanging Lamp)