|Yo Frankie! | Crystal Space Tutorials|
Using Crystal Space + CEL + B2CS + Blenderby Dariusz Dawidowski
This tutorial shows solution how to make something practical using Apricot pipeline but doesn't teach details. Also note that tools are under heavy developing and some names or techniques can be outdated when you reading this. Always please refer Crystal Space , CEL , Blender2crystal and Blender manuals.
Step 1 - Scene setup
Let's put main character and NPC on one scene, also setup simple scene and navigation graph covering it.
> Use the file in SVN: pro/tutorials/scripting_interaction_01.blend
Step 2 - Pursue
Time for first interaction. Sheep wandering around. But this is bloodthirsty sheep so she will start to pursue us when we close to her.
There is standard Property Class called Trigger (don't confuse with Quest Trigger). Trigger is capable to detect other entity in desired range using choosed shape like: box, sphere, beam and above mesh (defined outline scale around mesh). It can be positioned in 3d space or just automatically following entity's mesh. In case when other entity enter in trigger range it sends message cel.trigger.entity.enter, when this entity will leave range it sends message cel.trigger.entity.leave.
Set trigger for a sheep. Enable automatic following mesh position, enable monitoring for entity named 'camera' only - it's standard name of player character in B2CS. And set sphere radius to 5.
Lets make reaction for a trigger. Extend NpcTutorial Quest (for tutorial purposes I made NpcTutorial4.xml to not overwrite the old one). So during wandering state if message cel.trigger.entity.enter will income from Trigger Property Class - make debugprint on console 'I can see you !!'. After all operations you need to switch to some state to make a loop (ofcourse it makes no sense in oninit and onexit ofcourse) in this case we looping in wandering state.
> Use the file in SVN: pro/tutorials/scripting_interaction_02.blend
To the Python Property Class used by NPC add Action for pursuing:
def Pursue(self, args): """ cel action @param entity: chased entity name @type entity: string """ target_ent = Entities[args["entity"]] if target_ent: self.pathfinder.Pursue(target_ent, 0)
Next step is changing debugprit to real pursuing. Instead of two Rewards - let's make one - change to new state 'pursuing'.
In the begging of 'pursuing' ('oninit' Trigger) we executing Pursue Action with parameter 'camera'. Sheep start to pursue us.
Also in this state we detecting moment of going our of sheep's Trigger range and changien state back to 'wandering' then.
This way you can easily interact between entities, sending messages, and make complex logic liek for example using Property Class Damage, to hit other entity.
> Use the file in SVN: pro/tutorials/scripting_interaction_03.blend