"Transform.parent" won't transform.

Hello folks!

Apparently when i try to transform my Character with an moving Object (vehicle) it’s not transforming at all.
So the following script is being called once a Character tries to enter a Vehicle.

else if (playerInVehicle == false && whichcar != null)
                {
                    //gameObject.GetComponent(Shooting).enabled = false;
                    cameramain.transform.parent = whichcar.transform;
                    Char.GetComponent("PlayerMovement").enabled = false;
                    Char.GetComponent("MouseLook").enabled = false;
                    playerInVehicle = true;
                    cameramain.GetComponent(CarCamera).enabled = true;
                    cameramain.GetComponent(CarCamera).target = whichcar.GetComponent(CarController).centerOfMass.transform;
                    Char.transform.parent = whichcar.transform;
                    whichcar.GetComponent(CarController).iminside = true;
                    //Adam.SetActive(false);
                    //whichcar.GetComponent(SoundController).enabled = true;
                 
             
             
                }

Char is set to the current Character Clone.
whichcar is set to the nearest object he tries to enter.

EDIT: I just realized that the character is actually moving with the car, just really really slowly.The Character moves 1 inch in the direction the car is driving when the car moved already 50 meters.
Any ideas?

Is it possible that it just looks really odd because you’re not setting the player’s local position after parenting? Try:

Char.transform.parent = whichcar.transform;
Char.transform.localPosition = Vector3.zero;

And see if that works better?

The players position after parenting is where the player entered the Car.
I tried it with:

Char.transform.localPosition = Vector3(0,5,0);

This transforms the char on top of the car.

Vector3.zero made him transform under the car.

Apparently its the same issue again.

Do you have a collider or rigidbody you have to disable as well? I can’t seem to mimic your issue of the player just getting stuck or moving incredibly slowly.

And here’s how I parent, from inside the vehicle script with a linked Player transform:

    if(Input.GetKeyDown(KeyCode.Space) == true)
     {
       if (player.parent == null)
       {
         player.parent = transform;
         player.localPosition = Vector3.zero;
       }
       else
       {
         player.parent = null;
         player.position = transform.position;
       }
     }

Disabling Rigidbody and changing the code order did the trick! Thank you so much :slight_smile: