- Home /
Cant move rigidbody object when parented to another object
Hi there, I have a rigidbody capsule that I am controlling with the following code:
void FixedUpdate()
{
if (Input.GetKey("w")) rBody.MovePosition(transform.position + (transform.forward * moveSpeed * Time.fixedDeltaTime));
else if (Input.GetKey("s")) rBody.MovePosition(transform.position - (transform.forward * moveSpeed * Time.fixedDeltaTime));
if (Input.GetKey("a")) angle -= angleRateOfIncrease * Time.fixedDeltaTime;
else if (Input.GetKey("d")) angle += angleRateOfIncrease * Time.fixedDeltaTime;
rBody.rotation = Quaternion.Slerp(rBody.rotation, Quaternion.Euler(0, angle, 0), Time.fixedDeltaTime * rotationSpeed);
}
I also have a cube that acts as a rotating platform and it makes the capsule it's child when it collides with it so that the capsule moves along with it. But the problem is that when the capsule becomes the child I can't move/rotate the capsule anymore. Whats even more weird is that the platform is being rotated in the FixedUpdate method to give it a smooth rotation, but if it is rotated using the Update method, i can then move the capsule around, but the camera gets jittery.
Here is the code for the rotating platform:
//this allows the capsule to move but causes the camera to jitter
void Update()
{
// transform.Rotate(Vector3.up * speed * Time.deltaTime);
}
//this rotates the platform but doesn't allow the capsule to move
void FixedUpdate()
{
transform.Rotate(Vector3.up * speed * Time.deltaTime);
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Player")
{
other.transform.SetParent(playerHolder, true);
}
}
void OnCollisionExit(Collision other)
{
if (other.gameObject.tag == "Player") other.transform.parent = null;
}
Cant figure out how to solve this. I tried making the platform a rigidbody and added torque to it, but when it comes in contact with the capsule it causes other problems. Any help is appreciated :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612153602im_/https://answers.unity.com/themes/thub/images/avi.jpg)