- Home /
Simple Fracture ( Destruction )
Hello Guys,
I founded that script on the net : Simple Fracture and it suppose to create Destructible Environment. I apply it on a Cube that I flatten out and tag as "Target". And I put these lines of code in my Shoot Script :
if ( Hit.rigidbody.gameObject.CompareTag("Target")) {
SimpleFracture.FractureAtPoint( point : Vector3, force : Vector3);
}
The problem is that I get these errors.
For those of you who know how to use it maybe help with this question : Does the fracture script go on the object I want fracturing, and the call fracture in the same script?
Best Regards,
NbO
Answer by Lo0NuhtiK · Jan 22, 2012 at 10:02 PM
the function "FractureAtPoint" is to recieve a (point : Vector3) and (force : Vector3) when you call it.
Send it the information you want to send, not weird parameters or whatever---- point : Vector3 being the hit area, and force : Vector3 being the force you want to add.
Example :
var forceToFracture : Vector3 ; //set in inspector
if(Hit.rigidbody.gameObject.CompareTag("Target")){
SimpleFracture.FractureAtPoint(Hit.point , forceToFracture) ;
}
I'm assuming you're raycast-shooting... idk.. anyway Hit.point would be whatever contact-point vector3 you're hitting stuff at.
Hello, I tried what you said and I get this error now :
Assets/Scripts/Shoot.js(236,28): BCE0020: An instance of type 'SimpleFracture' is required to access non static member 'FractureAtPoint'.
Any Idea ?
I'm guessing you never assigned your SimpleFracture script in this script, and you're trying to access it directly by name. If that isn't the case, then idk.
var fracScript : SimpleFracture ;
function Start(){
fracScript = gameObject.GetComponent(SimpleFracture) as SimpleFracture ;
}
then in your if statement ->
fracScript.FractureAtPoint(Hit.point, forceToFracture) ;
EDIT :
just thought that the fracture script is probably on the hit object, so here's another guess since I don't really know where your scripts are and all that stuff.
put this in your if statement if this is the case.
if(whatever){
var frac : SimpleFracture ;
//!!EDITED--> add "collider" to the next line, that should work
frac = Hit.collider.gameObject.GetComponent(SimpleFracture) as SimpleFracture ;
frac.FractureAtPoint(Hit.point , forceToFracture) ;
}
In your edit you're wright, but it still didn't work. I edit my post to give a link to the source : http://forum.unity3d.com/threads/57994-Simple-Fracture-Script-v-1.01 .
NbO
EDIT: I get this error :
$$anonymous$$issingFieldException: Field 'UnityEngine.RaycastHit.gameObject' not found. Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) [...]
I added an edit in the code above here.
Not having "collider" on that line gives an error about 'gameobject' not being a member of 'raycasthit' ; so that's a different error than the one you posted...
If changing that line doesn't help, then idk... do some troubleshooting on your end since all the scripts and objects are on that side lol