StuckInPhDNoMore
StuckInPhDNoMore

Reputation: 2689

How can I force a child to only inherit the position of its parent while ignoring its parents rotation?

I want to create a simple mechanic where I control the rotation of an object that is childed to a parent.

Imagine a pot of water on the shoulder of a person. When the person jumps, the pot also changes position since it is a child. But I dont want to inherit the parent rotation. As I want to control the rotation of this child via script/gyroscope.

I know that a common solution to this would be to freeze the rotation in script within LateUpdate():

Vector3 InitPos;

void Start () 
{
    InitRot = transform.rotation;
}

void LateUpdate () 
{
   transform.rotation = InitRot;      
}

This would work, if I did not intend on controlling the rotation separately. Like mentioned above, I want to control the rotation of the child via touch or gyroscope. How can I achieve this?

Thanks

Upvotes: 0

Views: 680

Answers (1)

Akin Erkan
Akin Erkan

Reputation: 321

You can detach the child object from parent object, then make an empty gameobject under the parent object which will be target object, then with a basic follow script just follow the empty target object like

void Update()
transform.position = Vector3.MoveTowards(transform.position, following.transform.position,followSpeed);

or directly

 void Update()
    transform.position = following.transform.position

Upvotes: 1

Related Questions