Arrow transform breaks on shoot

Hello, I’m trying to make an archer controller but I couldn’t make it really.While Draw Arrow animation is playing I make arrow a child of right hand as in image.I modify local position and local rotation a little to make it look more natural.I’ve included code here.

arrow.transform.parent=main_hand;
arrow.transform.localPosition=new Vector3(.45f,-.1f,0);
arrow.transform.localRotation=rot;//rot is 8,90,90

Now evertyhing goes well until the shooting moment like in second image.When shoot command is given I set the arrow’s parent to null and send it forward.But when parent is set to null arrow always change position randomly.
I know it sounds stupid but I couldn’t make it’s parent null and keep it’s position same in world space at the same time.These are the codes I’ve tried.

arrow.transform.parent=null;

//arrow.transform.SetParent(null,false);

//arrow.transform.SetParent(null,true);

I think problem might be about scale or multiple parent(look hierarchy).How can I make it keep it’s world position while setting it’s parent to null.Thanks.

It’s not supposed to be doing that. You could try:

Vector3 arrPos = arrow.transform.position;
//set parent null
arrow.transfrom.position = arrPos;
1 Like

Unfortunately that didn’t work.I don’t know what’s wrong.

I would think you still have some parenting involved or a script is interfering in some way. You could try waiting a frame, and then setting it to it’s old position with a coroutine.

Woow.I made a new project and and tried it again and it worked.I think it was a bug.Thanks!

transform.SetParent(null,true);

Glad you got it working.