properly wake up bodies when a parameter changes, fixes #1740

This commit is contained in:
Juan Linietsky 2015-04-26 16:20:00 -03:00
parent 65c96a71bd
commit 3bcb930e8a
6 changed files with 37 additions and 2 deletions

View file

@ -279,6 +279,7 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant& p_va
_set_inv_transform(get_transform().inverse());
}
wakeup();
} break;
case Physics2DServer::BODY_STATE_LINEAR_VELOCITY: {
@ -286,12 +287,14 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant& p_va
//if (mode==Physics2DServer::BODY_MODE_STATIC)
// break;
linear_velocity=p_variant;
wakeup();
} break;
case Physics2DServer::BODY_STATE_ANGULAR_VELOCITY: {
//if (mode!=Physics2DServer::BODY_MODE_RIGID)
// break;
angular_velocity=p_variant;
wakeup();
} break;
case Physics2DServer::BODY_STATE_SLEEPING: {

View file

@ -201,6 +201,15 @@ public:
void set_active(bool p_active);
_FORCE_INLINE_ bool is_active() const { return active; }
_FORCE_INLINE_ void wakeup() {
if ((get_space() && active) || mode==Physics2DServer::BODY_MODE_STATIC || mode==Physics2DServer::BODY_MODE_KINEMATIC)
return;
set_active(true);
}
void set_param(Physics2DServer::BodyParameter p_param, float);
float get_param(Physics2DServer::BodyParameter p_param) const;

View file

@ -783,6 +783,8 @@ void Physics2DServerSW::body_set_applied_force(RID p_body, const Vector2& p_forc
ERR_FAIL_COND(!body);
body->set_applied_force(p_force);
body->wakeup();
};
Vector2 Physics2DServerSW::body_get_applied_force(RID p_body) const {
@ -798,6 +800,7 @@ void Physics2DServerSW::body_set_applied_torque(RID p_body, float p_torque) {
ERR_FAIL_COND(!body);
body->set_applied_torque(p_torque);
body->wakeup();
};
float Physics2DServerSW::body_get_applied_torque(RID p_body) const {
@ -814,6 +817,7 @@ void Physics2DServerSW::body_apply_impulse(RID p_body, const Vector2& p_pos, con
ERR_FAIL_COND(!body);
body->apply_impulse(p_pos,p_impulse);
body->wakeup();
};
void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2& p_axis_velocity) {
@ -826,7 +830,7 @@ void Physics2DServerSW::body_set_axis_velocity(RID p_body, const Vector2& p_axis
v-=axis*axis.dot(v);
v+=p_axis_velocity;
body->set_linear_velocity(v);
body->wakeup();
};
void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) {
@ -835,7 +839,7 @@ void Physics2DServerSW::body_add_collision_exception(RID p_body, RID p_body_b) {
ERR_FAIL_COND(!body);
body->add_exception(p_body_b);
body->wakeup();
};
void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) {
@ -844,6 +848,7 @@ void Physics2DServerSW::body_remove_collision_exception(RID p_body, RID p_body_b
ERR_FAIL_COND(!body);
body->remove_exception(p_body_b);
body->wakeup();
};