Game Development Reference
In-Depth Information
3. In the update method, if isEnabled() is true , it should parse scriptOb-
jects and call an update on all of the ScriptObjects.
Now, we have a flexible system where one ScriptObject can trigger another. We're
still lacking input and output effects though. One common way to trigger events is when a
player enters an area. So let's go ahead and add that functionality by performing the fol-
lowing steps:
1. Create a new class called EnterableTrigger , which extends Trigger .
2. This trigger needs a Vector3f field called position to define its place in the
physical world along with a getter and setter.
3. Add a BoundingVolume field called volume . In the setter method for this,
we should call volume.setCenter(position) .
4. Also, it needs a List<Spatial> called actors along with add and remove
methods.
5. Now, we should override the update method and then call the trigger if any
item in the actors list is inside volume :
if(isEnabled() && volume != null && actors != null){
for(int i = 0; i<actors.size(); i++ ){
Spatial n = actors.get(i);
if(volume.contains(n.getWorldTranslation())){
trigger();
}
}
}
6. We've taken care of the triggering now. Let's actually do something with that trig-
ger by creating a new class called SpawnTarget , implementing ScriptOb-
ject .
7. Like the EnterableTrigger class, the SpawnTarget class needs a posi-
tion field and also a Quaternion field called rotation .
8. The SpawnTarget class also requires a Spatial field called target and a
Boolean field called triggered to know whether it's been triggered yet or not.
9. We should also add a Node field called sceneNode to attach the target to.
10. In the trigger method, we should check whether it has been triggered already.
If not, we should set triggered to true and call onTrigger .
Search WWH ::




Custom Search