Sfoglia il codice sorgente

world: disable deactivation when Actor is marked as kinematic

Daniele Bartolini 6 anni fa
parent
commit
2f95eb6cc7
2 ha cambiato i file con 15 aggiunte e 2 eliminazioni
  1. 2 1
      CHANGELOG.md
  2. 13 1
      src/world/physics_world_bullet.cpp

+ 2 - 1
CHANGELOG.md

@@ -7,6 +7,7 @@ Changelog
 
 * runtime: added RenderWorld.mesh_set_material()
 * runtime: added World.unit_by_name()
+* runtime: fixed an issue that prevented kinematic actors to be controlled via the SceneGraph
 * runtime: fixed an issue where a regular Matrix4x4 was returned if Matrix4x4Box is called without arguments
 * runtime: removed "io" and "os" libraries from Lua API
 * runtime: small fixes and performance improvements
@@ -14,7 +15,7 @@ Changelog
 * tools: fixed a crash when entering empty commands in the console
 * tools: fixed an issue that prevented some operations in the Level Editor from being (un/re)done
 * tools: fixed an issue that prevented the data compiler from restoring and saving its state when launched by the Level Editor
+* tools: the Data Compiler will now track data "requirements" and automatically include them in packages when it's needed
 * tools: the game will now be started or stopped according to its running state when launched from the Level Editor
 * tools: the Properties Panel now accepts more sensible numeric ranges
 * tools: the Properties Panel now allows the user to modify most Unit's component properties
-* tools: the Data Compiler will now track data "requirements" and automatically include them in packages when it's needed

+ 13 - 1
src/world/physics_world_bullet.cpp

@@ -477,6 +477,8 @@ struct PhysicsWorldImpl
 		cflags |= is_static    ? btCollisionObject::CF_STATIC_OBJECT       : 0;
 		cflags |= is_trigger   ? btCollisionObject::CF_NO_CONTACT_RESPONSE : 0;
 		actor->setCollisionFlags(cflags);
+		if (is_kinematic)
+			actor->setActivationState(DISABLE_DEACTIVATION);
 
 		actor->setLinearFactor(btVector3(
 			(ar->flags & ActorFlags::LOCK_TRANSLATION_X) ? 0.0f : 1.0f,
@@ -618,8 +620,18 @@ struct PhysicsWorldImpl
 
 	void actor_set_kinematic(ActorInstance i, bool kinematic)
 	{
+		int flags = _actor[i.i].actor->getCollisionFlags();
+
 		if (kinematic)
-			_actor[i.i].actor->setCollisionFlags(_actor[i.i].actor->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+		{
+			_actor[i.i].actor->setCollisionFlags(flags | btCollisionObject::CF_KINEMATIC_OBJECT);
+			_actor[i.i].actor->setActivationState(DISABLE_DEACTIVATION);
+		}
+		else
+		{
+			_actor[i.i].actor->setCollisionFlags(flags & ~btCollisionObject::CF_KINEMATIC_OBJECT);
+			_actor[i.i].actor->setActivationState(ACTIVE_TAG);
+		}
 	}
 
 	bool actor_is_static(ActorInstance i) const