About Store Forum Documentation Contact
Donations:
327$/mo



Post Reply 
New question about Animation via KB.bp
Author Message
dbuman Offline
Member

Post: #1
New question about Animation via KB.bp
I am having some trouble once again.

I am learning alot about the programming in EE and am fascinated by the complexities.

I have a code which is supposed to call the animation via a Kb.bp command, however when i use it, it only moves it by one frame or a couple, but does not play the entire animation.

To understand what i mean, is I want to press a button to attack, but not hold it down, in such a way that it plays the animation in full.

Code:
if(Ms.bp(0))
      
      {  if((time_to_attack-=Time.d())<=0 && in_range)
               {                    
                        attack_motions.New().set(cskel,obj_file_path+"/human/attack.anim");
                        Player.hit();
                  time_to_attack=RandomF(1,1.5f);
               }
        
      
      
      REPA(attack_motions)
         {
            Motion &motion=attack_motions[i];
            
            if(!motion.updateAuto(3,3,1))attack_motions.clear();
            
               // if "hit" event occured (event's are set in Mesh Editor tool - Animation mode)
             // if finished playing then remove
        
   }    
      }

I have all of the necessary coding required for the command to work, however it doesn't execute with a full animation.
06-24-2011 06:24 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: New question about Animation via KB.bp
The animation only plays for a frame because your code only executes when the left mouse button is pressed, which only occurs in one frame until it is pressed again.

Instead of executing the animation code directly within the Ms.bp(0) if statement, you should just simply set a Boolean (Bool) variable to true. Then, if that variable is true, play the animation. Set it to false when it should no longer play.
(This post was last modified: 06-24-2011 07:41 AM by Driklyn.)
06-24-2011 06:55 AM
Find all posts by this user Quote this message in a reply
dbuman Offline
Member

Post: #3
RE: New question about Animation via KB.bp
would you care to show me in code form what you mean?

Im learning as I go lol
06-24-2011 07:21 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: New question about Animation via KB.bp
(06-24-2011 07:21 AM)dbuman Wrote:  Im learning as I go

That's why I purposely didn't show any code.. wink It will be better for you in the long run if you can figure this out on your own. It's not hard, Boolean variables are extremely easy. You already have the hard part down with the animation code..

Just read the last sentence in my previous post word for word. I tell you how to do it exactly.

Google "C++ Boolean variables" if you need help with using them. You'll find tons of information.
06-24-2011 07:39 AM
Find all posts by this user Quote this message in a reply
dbuman Offline
Member

Post: #5
RE: New question about Animation via KB.bp
all right!, thanks for the push, I managed to make a bool like you said
made it as 'attacking'

I have a feeling this piece of code will be useful to those wanting to make an action/rpg battle system.

Im working on making a hybrid action/rpg which will soon develop into a MMO. no classes, just weapons which you learn skills from using, just like materia from ff7. It may seem overpowered but if you spend enough time in a game, shouldnt you be?

heres my code!

Code:
if(Ms.bp(0))
     {if((time_to_attack-Time.d())<=0)
     {Attacking=1;
     time_to_attack = 1;} }
     if(Attacking==1)
     { attack_motions.New().set(cskel,obj_file_path+"/human/attack.anim");
     Attacking=0;
      Bool in_range=inAttackRange(AIs[0]);
      
         if(in_range)
               {                
                  hit(); // get AI looking direction
               }
   // check all the players

     }
      
      
      REPA(attack_motions)
         {
            Motion &motion=attack_motions[i];
            
            if(!motion.updateAuto(3,3,1))
            {attack_motions.clear();
             time_to_attack=0;
            }
            
               // if "hit" event occured (event's are set in Mesh Editor tool - Animation mode)
             // if finished playing then remove
        
   }

These are definitions I needed in the Struct(Player, Chr) section

Code:
Memb<Motion>   attack_motions;
bool Attacking;
void addDamage (Flt damage, Chr *src);
flt health;
flt living;

here are the corresponding actions needed to complete the player's side of battle:
Code:
void Player.create(Game.ObjParams &obj)
{  for(Game::ObjParamsPtr op=&obj; op; op=op->base())
      {if(CChar *name=Game::Objs(op))
      {
       obj_file_path=GetPath(name);  
      }
      }
   ctrl_pos=Player.pos();
   Player.health = 100;
   Player.living = 1;
   Attacking = 0;
   time_to_attack=0;
   super.create(obj);
  
}
void Player.addDamage(Flt damage,Chr *src)
{
      health -= damage;
      if(health <= 0)
         die();    
    

}
void Player::die()
{
   if(Player.health <= 0)
      {Player.living = 0;
       Player.respawn();
      }
  
  

   // when dying drop down active item moved by mouse

}

Bool Player::inAttackRange(Chr &ai)
{
   return Dist(pos(),ai.pos()) <= ctrl.radius()+ai.ctrl.radius()+0.6;
}

void Player::animate()
{
   __super::animate();
// apply idle   animations

   REPA(attack_motions)cskel.animate(attack_motions[i],true); // apply attack animations
}
void Player::respawn()
{
   if(Player.living==0)
   {
      Player.pos(ctrl_pos);
      Player.living = 1;
      Player.health = 100;
   }
  
  

   // when dying drop down active item moved by mouse

}
void Player::hit()
{
   Vec dir; SinCos(dir.z,dir.x,angle.x+PI_2); dir.y=0; // get AI looking direction

   // check all the players
   REPA(AIs)
   {  
      AI &mob=AIs[0];
      if(Dist(pos(),mob.pos()) <= ctrl.radius()+mob.ctrl.radius()+0.6)
         if(AbsAngleBetween(dir,mob.pos()-Player.pos())<=PI_3) // 60 degrees
            {mob.addDamage(RandomF(10,13),this);}    
   }
}

PS: I did not list the AI code as I barely altered it and my player.es code should work with the default AI code if you implemented it correctly.








EDIT: I know its not perfect, as it will probably bring errors if multiple enemies come in contact with you. I will modify the code later.

EDIT2: Change AIs[0] to AIs[i] and put int i; in the Struct(Player, Chr) section.
For a better effect on swings and attacks, change the angle from PI_3 to PI_6
(This post was last modified: 06-24-2011 08:54 AM by dbuman.)
06-24-2011 08:44 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: New question about Animation via KB.bp
Cool, glad to see you got it working. Good job!

However, this is wrong: "Change AIs[0] to AIs[i] and put int i; in the Struct(Player, Chr) section."

Using REPA automatically defines the "int i" for you, so don't make it apart of the class. Here's some more information about it: Loops.
06-24-2011 09:41 AM
Find all posts by this user Quote this message in a reply
dbuman Offline
Member

Post: #7
RE: New question about Animation via KB.bp
I meant the section with the mouse button pressed. there isnt a repa there, so it does need to be defined
06-24-2011 03:08 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #8
RE: New question about Animation via KB.bp
Your code is flawed.

Instead of looping through all AIs in Player::hit(), you should make a method Player::hit(AI &mob) which adds damage to a specific mob. Then, put the REPA before the inAttackRange method and, if is true, call hit(mob).

This way, you don't need the "int i" to be apart of your Player class; and, you will be able to remove the distance checking in Player::hit, as you would already know the mob is in range from when you called the Player::inAttackRange method.
06-24-2011 11:23 PM
Find all posts by this user Quote this message in a reply
Post Reply