[0.8.9][NK] Basic Physics (Layers, QueryMask, Simulation, Motion types)

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials

Physics layers

Assigning layer to physics component:
Registering new layer:
local layerID = EternusEngine.Physics.RegisterUserLayer("LayerName")
Disabling collision between 2 layers:
Eternus.PhysicsWorld:NKSetLayerCollisionsEnable(false, layerID, Eternus.PhysicsWorld.Layers.PLAYER)
Enabling collision between 2 layers: (by default all collision are enabled)
Eternus.PhysicsWorld:NKSetLayerCollisionsEnable(true, layerID, Eternus.PhysicsWorld.Layers.CHARACTER)
Disabling collision within the layer:
Eternus.PhysicsWorld:NKSetLayerCollisionsEnable(false, layerID, layerID)


Layer masks are used for world queries to filter objects based on layer(s).

Setting up LayerMask using BitFlags32:
local layerMask = BitFlags32()
Ray cast with LayerMask:
EternusEngine.Physics.RayCastCollect(position, direction, length, {}, layerMask)


Physics simulation is responsible for motion of objects and producing collision.

Enabling physics simulation:
Disabling physics simulation:

Motion types

There are 3 different motion types:
  • Dynamic - Active (physics based motion)
  • Keyframed - Inactive
  • Static - Disabled
The main difference between keyframed and static motion types is that static motion type has better performance, but it will take longer to switch to dynamic motion type.
When the object is going to switch between dynamic and keyframed motion types it is better to use keyframed motion type.
When the object is going to remain static it is better to use static motion type.

Setting motion type to dynamic:
Setting motion type to keyframed:
Setting motion type to static:
My Blog
  yt.png  t.png  
Sign In or Register to comment.