Example #1
0
void Joint2D::_update_joint() {

	if (!is_inside_tree())
		return;

	if (joint.is_valid()) {
		Physics2DServer::get_singleton()->free(joint);
	}

	joint = RID();

	joint = _configure_joint();
	Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias);
}
Example #2
0
void Joint2D::_update_joint(bool p_only_free) {

	if (joint.is_valid()) {
		if (ba.is_valid() && bb.is_valid())
			Physics2DServer::get_singleton()->body_remove_collision_exception(ba, bb);

		Physics2DServer::get_singleton()->free(joint);
		joint = RID();
		ba = RID();
		bb = RID();
	}

	if (p_only_free || !is_inside_tree())
		return;

	Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
	Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;

	if (!node_a || !node_b)
		return;

	PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
	PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);

	if (!body_a || !body_b)
		return;

	if (!body_a) {
		SWAP(body_a, body_b);
	}

	joint = _configure_joint(body_a, body_b);

	if (!joint.is_valid())
		return;

	Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias);

	ba = body_a->get_rid();
	bb = body_b->get_rid();

	Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
}