Get axe/arrow to stick to object
I'm trying to get an object/projectile to stick to a tree, I've looked up other answers and have tried to implement, still don't understand why it's not working.
-Rigidbody on Axe object.
-Rigidbody and Box Collider Trigger on tip of axe edge in an empty child object of the Axe object.
-Script attached to child object with Trigger.
-Tags are all appropriately set.
-The objects make physical contact, it just doesn't stick when the trigger hits or even Debug.Log.
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Climbable")
{
Debug.Log("grappled");
Rigidbody pb = this.GetComponent<Rigidbody>();
Rigidbody r = axe.GetComponent<Rigidbody>();
//Collider x = axe.GetComponent<Collider>();
r.isKinematic = true;
pb.isKinematic = true;
// pb.velocity = Vector3.zero;
axe.transform.parent = other.transform;
}
}
If you've got no errors and your debug.log line isn't printing, the only answer I could see is typo in your tag comparison.
Sorry to be condescending but if you're not getting the debug line out then you're not entering the IF statement.
Further, add a debug line above the if statement to log if the collider triggers, just to be sure.
is your axe head box collider set to isTrigger?
If none of this applies, maybe screenshots and code of relevant objects like Axe/Tree?
I'm getting the trigger to trigger now, the if statement is being called, problem is it's being called mid-air without hitting any colliders. So the axe gets instantly stuck in mid-air after a short distance.
all in all that's great news!
Check the bounds of all colliders. Ensure the axe head isn't colliding with the axe body?
I haven't checked this but as far as i know you should be able to debug.log (other.transform.name); To tell you the gameObject name of what it collides with.
Your answer
Follow this Question
Related Questions
Mess up with triggers, colliders and all this stuff :( 0 Answers
How can I simulate a thread? 1 Answer
Scene freezes when I restart level 0 Answers
Unity keeps crashing in while loop 1 Answer
Freeze 2D GameObject 0 Answers