- Home /
Script for counting score in Archery game working weird
Hello guys, I am having a problem with setting the score for my archery game. I have attached a script to my targets but it seems to work weirdly. It increases score and displays in the console when the arrow is hit from near the target and is not stuck in it. But there is no difference in score if an arrow is hit from far and the is stuck in the target. Please help.
int score = 0;
void OnCollisionEnter(Collision collision)
{
score++;
print("Hit. Current Score is " + score);
}
}
It's not a script issue but collission issue, check if your arrow is actually hitting the collider.
I have tried everything I can with collisions but it doesn't seem to work. The arrow passes through the target and gets stuck in the target sometimes. The score is increased only when the arrow passes through the target (which happens only when the shooter is close to the target). I have added mesh colliders to both arrow and target(cylinder) and made target a trigger. Also, added rigidbody to the arrow. Nothing seems to work. Please help.
Is the target having an non-kinematic rigidbody attached? Arrow & target's collider both not set to istrigger
Neither target nor arrow has a rigidbody attached to it. I tried adding a rigidbody but it didn't help much. Any other possible solutions, please.
Collision events are only sent if one of the colliders has a rigidbody and one of the rigidbody is$$anonymous$$inematic is set to false So try adding a rigidbody to the target board and check if is$$anonymous$$inematic is untick and isTrigger should be untick too https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
Answer by ChayaSri · Dec 04, 2017 at 12:30 AM
Thank you. Will see what changes I can do to the collider.
Answer by Vilhien · Dec 04, 2017 at 09:09 PM
Just to clarify, is the arrow made up of just one object? could it be that the tip hitting it isn't registering the same as the arrow stock? I think I remember reading something a bit back about using two object for an arrow flight. Not sure if that was related but got me thinking about the multi object thing.
Your answer
Follow this Question
Related Questions
Score not updating 0 Answers
Scoring Points. 1 Answer
Score no longer works after backing up my game 0 Answers
How can I make my score editable? 1 Answer