S2ENGINE HD
1.4.6
Official manual about S2Engine HD editor and programming
|
Just as items, weapon are components of player invenory.
They are a little different from items because items are used one time and just when selected from inventory, while weapons remains in player hands after selected and can be shot any time it is needed
WeaponTAGs are the corresponding itemTAGs but for weapons.
They are the weapon representation inside the scene and they are needed for letting player pick up the related weapon.
Weapons are corresponding itemObjects but for weapons.
Differently from ItemObjects, Weapons must not be in form of prefabs to be instanced when selected, but they are placed inside the scene, precisely Weapons are always on the player's hands.
This means that the Weapon object must be attached to playerCharacter hands node.
PlayerCharacter hides all weapons at start, a weapon is showed only if it is taken and when it is selected from inventory.
To be 100% convincing a weapon must owns an sh2 model containing 4 nodes, BUT you can omit then if you want:
Usually loader node is used in this way:
WeaponAmmoTAG are special kind of TAG used for weapon ammo.
They are implemented in a very simple way: when taken, automatically a new loader is added to the corresponding weapon, even if player haven't that weapon yet. This is achieved making the weaponAmmoTAG to send a SUPPLY_AMMO message to the player when it receives an ACTION message from the player. A weaponAmmoTAG has a reference to the weapon object it must supply loaders.
Weapons are the most complex part of the DLC. This is due to the fact that weapons are composed by many parts (models, animations, logic, spawing objects such as projectiles, particle systems, etc..) and all these must interface with GameMachine for letting user to have the maximum control.
When player takes the weapon ( i.e. it sends the ACTION message to the aimed weaponTAG ), weaponTAG replies with a ARM message specifying the related weapon object (attached to players hand) name and weapon caption into the message content.
Before using the weapon, of course, it must be selected and grabbed from inventory. There are 2 ways for grabbing weapons from inventory:
ChangeWeaponAxis
command (that can be set in the player character parameters).When a weapon is grabbed playerCharacter sends a CHANGE_WEAPON event to its FSM (see Player Sending Events) for notifying the FSM that a new weapon has been choosed, this is useful, for example, in the case you want player to perform an animation for changing weapon.
When the FSM receives the event CHANGE_WEAPON it can send the selectWeapon message to the player for making it to hide previous weapon and showing the current selected weapon, also when playerCharacter receives the selectWeapon message it replies to FSM with an event named weapon_weaponName where weaponName is the name of the current selected weapon (see Player Sending Events), this is needed to inform FSM what is the current selected weapon, so FSM can change state according to the new weapon.
The image below shows the flow of this mechanism, taken from the playerCharacter asset provided into the EasyGame sample project:
To shoot projectiles weapon must receive a message called shoot. When receiving this message a weapon spawn various prefabs:
ProjectilePrefab
parameter of the Weapon object class.BulletBoxPrefab
parameter of the Weapon object class.MuzzlePrefab
parameter of the Weapon object class.How to make weapon receiving shoot message?
Usually the projectile is shot just at the beginning of the shooting animation so you could proceed in this way:
Weapon can also receive a message called Throw. When receiving this message the weapon sends an HIT event to hit objects in 2 ways, basign on the parameter MeleeFromCamera:
MeleeFromCamera
is FALSE: in this case all object that are inside a range from player (defined by MeleeRange
parameter) and are in front of player receive the HIT event. It is useful for 3dr person character gamesMeleeFromCamera
is TRUE: in this case a raycast from camera node is done and an HIT event is sent to collided object. This mode is useful in fist person games.meleeNode
parameter must be specified. It is the node from which are generated the effects of the hit (for example particle systems). It must be on the weapon. The following image is an example, taken from the mace.sh2 file used into the demo project game, about how melee node must be made: