- Home /
Question by
maidi · Jan 08, 2017 at 06:22 PM ·
rigidbody.addforcerigidbody.velocity
Move object invertically to another
I want to close a drawer when another drawer is opened and vice versa. I'm only interested in the z-Axis Movement. My Script doesn't work so far. The other drawer doesn't move at all. The if-statement is called so myVelocity is more or less 0 when the drawer is moved.
private Vector3 myVelocity;
private Vector3 otherVelocity;
public GameObject otherDrawer;
void Update () {
otherVelocity = otherDrawer.GetComponent<Rigidbody> ().velocity;
myVelocity = GetComponent<Rigidbody> ().velocity;
if (myVelocity.z > 0 || myVelocity.z < 0) {
otherVelocity.z = myVelocity.z * -10f;
}
}
I'm working with the HTC Vive.,I want to add an inverse force to an object if another respective object is moved. To be more precise a drawer should open up if another drawer is closed so I'm only interested in the z-axis movement. I'm using the HTC Vive.
This is my script so far but it doesn't work. The other drawer doesn't move at all. The if-statement is called so myVelocity.z is more or less 0 when I move it.
private Vector3 myVelocity;
private Vector3 otherVelocity;
public GameObject otherDrawer;
void Update () {
otherVelocity = otherDrawer.GetComponent<Rigidbody> ().velocity;
myVelocity = GetComponent<Rigidbody> ().velocity;
if (myVelocity.z > 0 || myVelocity.z < 0) {
otherVelocity.z = myVelocity.z * -10f;
}
Comment