update
This commit is contained in:
10
script_rigidbody_trigger/README.md
Normal file
10
script_rigidbody_trigger/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
Rigid body set to:
|
||||
- Active dynamic
|
||||
- Axis and rotation locked (linear and angular factor)
|
||||
- Trigger/Ghost checked making this a trigger instead of a collision object
|
||||
- Force deactivation unchecked to make sure physics engine keep the rigid body active
|
||||
- Trigger script checks for overlapping rigid bodies on each update
|
||||
|
||||
## How to test
|
||||
Move the box around using WASD+QE.
|
||||
When box is overlapping sphere the icoshpere object is visible, otherwise it's hidden.
|
||||
40
script_rigidbody_trigger/Sources/lnx/Trigger.hx
Normal file
40
script_rigidbody_trigger/Sources/lnx/Trigger.hx
Normal file
@ -0,0 +1,40 @@
|
||||
package lnx;
|
||||
|
||||
import iron.object.Object;
|
||||
import iron.Scene;
|
||||
import leenkx.trait.physics.PhysicsWorld;
|
||||
import leenkx.trait.physics.RigidBody;
|
||||
|
||||
class Trigger extends iron.Trait {
|
||||
|
||||
var rb:RigidBody;
|
||||
var physics:leenkx.trait.physics.PhysicsWorld;
|
||||
var obj:Object;
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
|
||||
notifyOnInit(function() {
|
||||
rb = object.getTrait(RigidBody);
|
||||
physics = leenkx.trait.physics.PhysicsWorld.active;
|
||||
obj = Scene.active.getChild("Icosphere");
|
||||
});
|
||||
|
||||
notifyOnUpdate(function() {
|
||||
// TODO: replace with notifyOnCollisionEnter or notifyOnTriggerEnter once implemented
|
||||
// ref: https://github.com/leenkx3d/leenkx/issues/331
|
||||
var rbs = physics.getContacts(object.getTrait(RigidBody));
|
||||
var visible = false;
|
||||
|
||||
if (rbs != null) {
|
||||
for (rb in rbs){
|
||||
if(rb.object.name == "Cube"){
|
||||
visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
obj.visible = visible;
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
script_rigidbody_trigger/script_rigidbody_trigger.blend
Normal file
BIN
script_rigidbody_trigger/script_rigidbody_trigger.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user