Aento
July 10, 2019, 9:58am
1
I have animated object( warrior with idle animation) when I shoot him with an arrow I want that arrow will be child of hitted collider.
transform.position = raycastHit.point;
transform.Translate(0, 0, -tailOffset/2, Space.Self); // move arrow backward
transform.SetParent(raycastHit.transform, true);
When I delete setParent row ,arrow stop on expected point.
But when I set parent, arrow moves to other position and slightly change rotation.
When I disable animator on a warrior (body behind first one) and shot arrow with setParent it works as it should, arrow stay in correct place.
Please help I spent a week on this issue and have no idea what to do now.
Sorry for my english )
Set parent first, then change position and offset.
Are you doing it in update? Is your character animated? Animation values are applied inbetween update and late update. Try to reparent in late update, after animation state is applied to bones.
Aento
July 10, 2019, 12:14pm
5
YOU are my HERO!!!
I did it with coroutine. After moving setParent to late update everything work like a charm!
Thank you.
I use trigger pattern in cases like this one.
private void OnCollisionEnter(Collision other) {
_triggerReparent = true;
_targetParent = other.transform;
}
private void LateUpdate() {
if(_triggerReparent) {
transform.SetParent(_targetParent);
_triggerReparent = false;
}
}
but coroutines are OK too