- Home /
Setting thrown object to kinematic after hitting target?
Hi everyone! I am making an axe throwing game for VR, and am having a little trouble getting this part to work. I have a grabbable object that should stick in place once it hits the mesh of the target. This is the code I'm working with:
public class TargetScore : MonoBehaviour { //Set public GameObject Axe;
private void OnTriggerEnter(Collider other)
{
//when object comes into contact with target
if (other.gameObject.name == Axe.name)
{
GetComponent<Rigidbody>().isKinematic = true;
ScoreManager.score++;
}
}
But the axe will not stick nor will the score increment. What am I missing? Thank you!
Answer by Eno-Khaon · Nov 24, 2020 at 07:11 AM
Well, let's take this one step at a time:
if (other.gameObject.name == Axe.name)
This suggests that this script is attached to the Target, and that it's watching for the Throwing Axe.
GetComponent<Rigidbody>().isKinematic = true;
Then, you're setting the Target to be kinematic.
You should set that on the Throwing Axe instead.
other.gameObject.GetComponent<Rigidbody>().isKinematic = true;
Thank you so much! This worked! I see how that I was basically setting the target as kinematic before.