- Home /
Link two rigidbodies
I have two rigidbodies, one cube and one is the player. If the cube is pushed towards the ground, I want the character to go up. How can I do this?
I've tried using OnCollisionStay on the cube to push the player up characterBody.AddForce(collision.relativeVelocity * -1);
but this doesn't work very well and barely moves the player
Adding the following code snippet into the component on the player could work:
Rigidbody rb;
public Rigidbody linkedRB;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.velocity = new Vector3(rb.velocity.x, -linkedRB.velocity.y, rb.velocity.z);
}
This didn't work because the cube moves with the player
Can you try elaborating on exactly what you are trying to do?
e.g. Do you want the player to have full control and the box going down to boost the player's movement up? Or does the player only go up when the box goes down? Which direction is "up" in your scenario (x, y, or z)?
Answer by swanijam · Nov 02, 2018 at 06:31 PM
Is this trampoline situation? or an elevator where the cube is the counterweight? It's unclear what the purpose or circumstance of the collision is.
Your answer
Follow this Question
Related Questions
Physics rigidbody.addforce 0 Answers
RigidBody.AddForce causes capsule collider to trip on a surface with friction 2 Answers
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
Launch arc with physics/rigidbody problem and on Unity's internal code 1 Answer
Flight Control Issues 0 Answers