[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:
self:NKGetPhysics():NKSetLayer(EternusEngine.Physics.Layers.DEFAULT)
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)

LayerMask

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

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

Simulation

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

Enabling physics simulation:
self:NKGetPhysics():NKEnableSimulation()
Disabling physics simulation:
self:NKGetPhysics():NKDisableSimulation()

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:
self:NKGetPhysics():NKSetMotionType(PhysicsComponent.DYNAMIC)
Setting motion type to keyframed:
self:NKGetPhysics():NKSetMotionType(PhysicsComponent.KEYFRAMED)
Setting motion type to static:
self:NKGetPhysics():NKSetMotionType(PhysicsComponent.STATIC)
My Blog
jc.png
  yt.png  t.png  
Sign In or Register to comment.