Hi im trying to make my darts stick into the dartboard after being launched and instead they just bounce off as if its not even running my code
heres the code im using to handle collision and this script is attached to the dartboard
public class dartscollision : MonoBehaviour {
public Rigidbody Dart;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision theObject){
if(theObject.gameObject.name==“dart”){
Dart.useGravity = false;
Dart.velocity = Vector3.zero;
Dart.angularVelocity = Vector3.zero;
}
}
}
i turned the colliders off and the darts fly through the dartboard
maybe a more accurate description of what im after would help
im trying to get the dart to hit the board then freeze in place so theres no force acting on them and they no longer have any velocity.
Are the lines in your if-clause executed?
If so, how do you assign the ‘Dart’ variable?
I think you would need to add a line like Dart = theObject.rigidbody.
Simply do a Debug.Log(“Test”); inbetween the bracets.
If you dropped the dart prefab on it it wont work, then your code tries to alter the asset not the actual gameobject.
That sounds like itll be my problem i did just put the dart prefab onto it in the editor how would i get it to alter the actual object when it hits the dartboard?
Did you check if those lines get executed?
Because if you instantiate a prefab the name normally is something like prefabName(Clone) which would mean that your if clause would fail. Check this.
after looking into it and doing the Debug.Log(“test”) in several locations i have found that it is not running the OnCollosionEnter method. however i do not know why is isnt running this method or how to fix it
Sorry, once there is a collision with the board, turn of the darts collider, set its velocity to 0 etc. Or, just make the board a trigger. Then you do not have to turn off any colliders.