예제 #1
0
bool KinematicBody2D::can_move_to(const Vector2& p_position, bool p_discrete) {

	ERR_FAIL_COND_V(!is_inside_scene(),false);
	Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(get_world_2d()->get_space());
	ERR_FAIL_COND_V(!dss,false);

	uint32_t mask=0;
	if (collide_static)
		mask|=Physics2DDirectSpaceState::TYPE_MASK_STATIC_BODY;
	if (collide_kinematic)
		mask|=Physics2DDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
	if (collide_rigid)
		mask|=Physics2DDirectSpaceState::TYPE_MASK_RIGID_BODY;
	if (collide_character)
		mask|=Physics2DDirectSpaceState::TYPE_MASK_CHARACTER_BODY;

	Vector2 motion = p_position-get_global_pos();
	Matrix32 xform=get_global_transform();

	if (p_discrete) {

		xform.elements[2]+=motion;
		motion=Vector2();
	}

	Set<RID> exclude;
	exclude.insert(get_rid());

	//fill exclude list..
	for(int i=0;i<get_shape_count();i++) {


		bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),motion,0,NULL,0,exclude,0,mask);
		if (col)
			return false;
	}

	return true;
}