combat code problems

Posted By: Doc_Savage

combat code problems - 09/26/12 14:10

hi there, i have a big issue with combat, i have a player with a sword, he is using the c_trace function to hit an enemy and deal damage, 5 points. that is all fine and working, the problem is, he hits multiple times while his sword is passing through the enemy and ends up dealing 15 or 20 damage points!! it is so frustrating, i cant find a single thing to thwart this, can anyone help? i would love for the enemy to be dealt one unit of damage each time the sword passes through him.




also is there a way to have the animation set up so you click the mouse and release, he swings his sword and stops when the animation is done? and while holding down the mouse button he swings continually? like in the game diablo.



i know this is a lot to ask but i would like a few hints here, ive done a LOT of research and tried hard to solve it through expiramentaion. ive been on these problems for 3 weeks. hopefully i can get some results from the pros laugh thanks guys. im hoping you can help me with these problems and thank you for your time.
Posted By: GameScore

Re: combat code problems - 09/26/12 14:28

you should post your code
we must see what you done there
Posted By: Doc_Savage

Re: combat code problems - 09/26/12 15:50

i cant unfortunatley, im away from home, but its your basic c_trace function on a sword model. i hope someone can help me with those problems anyway.
Posted By: Superku

Re: combat code problems - 09/26/12 16:45

Don't trace along the sword's blade, only perform one box-trace at the middle of the animation, or check if any of the enemies are in front of the player for weapons with splash damage.
Posted By: Doc_Savage

Re: combat code problems - 09/26/12 17:00

can you please show an example of that? ive never heard of this strategy. i would be very appreciative. also any idea on my animation problem?
Posted By: Superku

Re: combat code problems - 09/26/12 17:09

action act_player()
{
while(1)
{
if(mouse_left)
{
my.skill20 = 0;
my.skill21 = 1;
while(my.skill20 < 100)
{
my.skill20 += 10*time_step;
ent_animate(me,"attack",my.skill20,0);
if(my.skill20 > 50 && my.skill21)
{
my.skill21 = 0;
VECTOR temp;
vec_set(temp,vector(100,0,0)); // 100 = weapon range
vec_rotate(temp,vector(my.pan,0,0));
vec_add(temp,my.x);
c_trace(my.x,temp,IGNORE_ME | IGNORE_PASSABLE);
if(you)
{
if(your._type == type_enemy) //identify your enemy somehow, where _type is defined as skill100 or something like that
{
your.health -= 25;
}
}
}
wait(1);
}
}
move & turn;
wait(1);
}
}
Posted By: Doc_Savage

Re: combat code problems - 09/26/12 17:19

oh WOW. ok. so this is how to do the trace in the middle of the animation huh? so ctrace is a bad idea then.. hm.. ok. im assuming this is a player code. i totally get it now.

edit: i just remembered i have the enemy identified with an entity pointer, will that work here?
Posted By: Ch40zzC0d3r

Re: combat code problems - 09/26/12 17:35

Originally Posted By: Doc_Savage
oh WOW. ok. so this is how to do the trace in the middle of the animation huh? so ctrace is a bad idea then.. hm.. ok. im assuming this is a player code. i totally get it now.

edit: i just remembered i have the enemy identified with an entity pointer, will that work here?


When your enemies are all having the same entitypointer (what I dont think) then yes.
Posted By: Doc_Savage

Re: combat code problems - 09/26/12 17:40

well funny enough, im having trouble with more than one enemy in the game, some things sync like alert distance and stuff. any idea how to separate them?
i need to know how to individualize them. should i be using more than one entity pointer or what?
Posted By: Superku

Re: combat code problems - 09/26/12 17:43

Quote:
i just remembered i have the enemy identified with an entity pointer, will that work here?

Quote:
well funny enough, im having trouble with more than one enemy in the game, some things sync like alert distance and stuff. any idea how to separate them?

Don't use global pointers for that, just handle individual things, attributes and the like with skills.
Posted By: Doc_Savage

Re: combat code problems - 09/26/12 17:48

oh ok... what should i use instead?
Posted By: Superku

Re: combat code problems - 09/26/12 20:05

Originally Posted By: Superku
Don't use global pointers for that, just handle individual things, attributes and the like with skills.
Posted By: exile

Re: combat code problems - 09/27/12 09:05

Superku is right, the way I handled my combat in my "Tales of Symphonia" styled combat game/project is like this...

-Player swings sword. Theres a trace going from the base of the sword to the tip.

-When it comes in contact with an entity, I check to see what kind of entity it is with skills, like;
Code:
if(hit.entity)//Did I come in contact with an entity?
{
   enemy_hit = hit.entity;//Set a pointer to the enemy I hit
   if(enemy_hit.skill10 == 2) //Is the thing I hit an enemy?
   {
      enemy_hit.skill11 = 1; //Let the enemy know I am hitting it
   }
}


-What this does is simply setting a pointer to whatever I am coming in contact with, then checking to see if what I am hitting is an "enemy" type. If it is, I set its "I am being hit" skill (skill11 in this case) to 1.

-In your enemy code, you then just have to set it like...
Code:
function enemy()
{
   my.skill10 = 2;
   while(my.health>0)
   {
      if(my.skill11==1)//Checking to see if the enemy has received a "hit" confirm
      {
         //Do hit animations, reduce damage, etc
         my.skill11 == 0; //Reset the skill
      }
      wait(1);
   }
}



-I added a "stun" skill to my enemies which determined how long the hit frame should last between hits. So say if I have a stun of 40, then there will be a wait time of 40 frames unil the enemies "hit" skill gets reset to 0.


This is the way I did it, and it may not even be the "best" way to do it. But it works, and if anyone out there can give this guy some better advice please do so. I dont like giving misinformation laugh
Posted By: Doc_Savage

Re: combat code problems - 10/04/12 21:06

thank you all! ive solved it thanks to you all. than you.
© 2023 lite-C Forums