Darts game

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;
}
}
}

any help would be much appreciated

Turn off the colliders.

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.

i dont know how to check if its executing those lines
the Dart variable is assigned in the unity editor to be the Dart asset that i have

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?

Inbetween the if clause do Dart = theObject.rigidbody

still same as before the dart is just bouncing off the 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.

How can i check if its executing those lines?
its instantiating the prefabs fine the only problem i have is with the collision

As i already said, do Debug.Log(“test”) inbetween the brackets to see if those lines get executed. If nothing appears in the log your if-clause fails.

it doesnt look like its executing those lines as i cant see test appearing anywhere in the the editor log

So that means the gameobject probably isn’t called “dart”. Use tags instead or make sure that you rename the gameobject after instantiating to “dart”

the prefab does have the tag dart and in the script that instantiates the darts it assigns them the name dart

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.