I'm trying to put an object (for example a sword) in my player's hand. To do so i set the player's hand transform as the object's parent, in order to have the same movement for the object and the hand. No problem here.
The real issue starts as soon as i set the sword position to the hand position. My player starts to move backward.
One of my doubt was that my sword has a rigid body and my player too, so it could have an impact on it because I know that you can set a rigid body as a rigid body child.
So I was wondering if it's the right way to do it.
Edit
Here is my script to pickup an item:
public void PickupItem()
{
Ray interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit interactionHit;
if (Physics.Raycast(interactionRay, out interactionHit, InteractionMaxDistance))
{
if (interactionHit.collider.tag == "LootableItem")
{
Item item = interactionHit.collider.gameObject.GetComponent<Item>();
GetComponent<CharacterStats>().AddStats(item.Stats);
_hand = TransformUtil.FindChild("mixamorig:RightHandMiddle1", _player);
item.GetComponent<Rigidbody>().isKinematic = true;
item.GetComponent<Rigidbody>().useGravity = false;
item.transform.parent = _hand;
item.transform.position = _hand.position;
item.transform.rotation = _hand.rotation;
}
}
}
My script for player movement :
void Update()
{
float translation = (Input.GetAxis("Vertical") * Speed) * Time.deltaTime;
float rotation = (Input.GetAxis("Horizontal") * RotationSpeed) * Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
if (Input.GetButtonDown("Jump"))
{
_animator.SetTrigger("triggerJump");
return;
}
if (Math.Abs(translation) < 0.01 && Math.Abs(rotation) < 0.01)
{
Speed = 1;
}
else
{
if (Input.GetKey(KeyCode.LeftShift))
{
Speed = 4;
RotationSpeed = 150;
}
else
{
Speed = 2;
RotationSpeed = 200;
}
}
_animator.SetFloat("speed", Speed);
_animator.SetFloat("rotation", rotation);
_animator.SetFloat("translation", translation);
}
I took my character from Mixamo, same for the animaitons.