The game's combat system


#1

This is the part that confuses me the most. So far there are three weapons in the game, all are borrowed from playcanvas’s “axe pack”. From what I know there will be halves to the game’s combat system. The first half may be a script using the global variable system to assign each weapon a specified amount of damage that it can do. The second half of the system will be a script in which each enemy will be programmed with a copy of. In this script each enemy will be assigned a specific amount of health that drops each time the enemy collides with the weapon model. Take note that this will use the collision system to let the enemy know he has been struck by the weapon. The problem is I have not much of a clue as to how either of these scripts will be coded. Any help will be appreciated. Thanks. Also as of now this is not mandatory, but how will I add a part to where if the player is wearing armor, he still takes damage but a large percentage of it is reduced?


#2

You told that you use keys to change weapon right? When you press the key you have also to set the damage variable for the weapon what you equip, is not necessary to have a script for each weapon. For the enemy damage, in the script that check the collision you can drop the health too.
To set a global variable you have to declare it at the top of the script, before every function{}, if you need to use it in another script you just use it like this window.variableName


#3

can you give me an example as to how this will work?


#4

ok let’s say you have a js for your character that is named player.js , before the

pc.script.create(“player”, function(app) {

you insert

var weaponDamage=0; (or any value for the default weapon

in the script where you use the keys to change the weapon you should have something like this

if (context.keyboard.wasPressed(pc.input.KEY_8)){

in the code here you insert

window.weaponDamage=300;

}

this way you change the value of the damage a weapon can do


#5

Now how would I do the half for the enemy’s script involving damage?


#6

Take a look at this project @ayrin made , https://playcanvas.com/project/352037/overview/kallen-supremacy ,
it helped me out alot for my project maybe it will help you to.