Thread: Leap/Jump attack problems

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    117

    Leap/Jump attack problems

    Hi!

    I want my custom npc to leap/jump towards his enemy.

    From void HandleAnimEvent():
    Code:
    case SKULK_LEAP:
                {
                    CBaseEntity@ eTarget = self.m_hEnemy;
                    Vector enemyPos = eTarget.pev.origin;
                    enemyPos.z += eTarget.pev.maxs.z;
                    Vector vecToEnemy = (enemyPos - self.pev.origin).Normalize();
                    //self.pev.velocity = vecToEnemy * 200;
                    self.pev.velocity = g_Engine.v_forward * 2000;
                }
    Problem: Sometimes he does not get any velocity. He just plays his jump animation.
    I tried just giving him forward velocity in case he just lost his target or something.
    Any ideas? :-/

  2. #2
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,426

    Re: Leap/Jump attack problems

    Problem: Sometimes he does not get any velocity. He just plays his jump animation.
    Guessing you have "Other attack" AnimationEvents (Claw, bite, spit, etc), a Control/Decision routine such as "Ideal Attack" and a separate "Range Attack" routine.

    If it only happens sometimes, then sounds like some sort of conflict between "Range" routine and "Ideal Attack" routine.
    (Some other attack should be happening instead of Jump? i.e. You only specify eTarget.pev.maxs.z in your code snippet or a "up" Jump, so forward velocity & range must be somewhere else.).
    Last edited by wolf-3d; 13-05-2018 at 06:33 AM.
    Regards
    Wolf-3D

  3. #3
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    117

    Re: Leap/Jump attack problems

    Code:
    switch	(self.m_MonsterState)
    		{
    			case MONSTERSTATE_COMBAT:
    			{	
    				pev.movetype = MOVETYPE_STEP;
    				CBaseEntity@ pTarget = self.m_hEnemy;
    				float distToEnemy = ( pev.origin - pTarget.pev.origin).Length();
    			
    				if (self.HasConditions( bits_COND_HEAVY_DAMAGE ))
    				{
    					return BaseClass.GetScheduleOfType ( SCHED_TAKE_COVER_FROM_ENEMY );
    				}
    			
    				if ( distToEnemy < 96 && self.HasConditions( bits_COND_CAN_MELEE_ATTACK1 ))
    				{
    					return BaseClass.GetScheduleOfType (SCHED_MELEE_ATTACK1);
    				}
    				else if( distToEnemy >= 96)
    				{
    					switch ( Math.RandomLong ( 0, 1 ) ) 
    					{
    						case 0:
    						return BaseClass.GetScheduleOfType (SCHED_MELEE_ATTACK2);
    						case 1:
    						return BaseClass.GetScheduleOfType (SCHED_CHASE_ENEMY);	
    					}
    				}
    								
    			}			
    		}
    
    		return BaseClass.GetSchedule();

    As you can see the leapattack is MELEE_ATTACK2, and is only scheduled if the npc is far enough from target.
    The velocity is given in the animation event (code in first post).

    It is really strange. In my testmap i have a room with 4 of these npcs. Either they ALL get the velocity when using the leapattack or none of them.

  4. #4
    func_vehicle enthusiaist w00tguy123's Avatar
    Join Date
    Dec 2006
    Location
    U.S. West
    Posts
    1,541

    Re: Leap/Jump attack problems

    Try setting basevelocity instead of velocity. I had to do this in the TakeDamage callback for a custom ent or else it wouldn't budge most of the time.
    Love,
    w00tguy

  5. #5
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,426

    Re: Leap/Jump attack problems

    Maybe as per W00tGuy basevelocity will fix it but also:

    case MONSTERSTATE_COMBAT:
    {
    pev.movetype = MOVETYPE_STEP; // Normal NPC, walk, claw, bite etc.
    ...
    }

    But then you want a "jump", so I would expect to see a change to at least one of the following
    "Friction, Gravity or Movetype" in SKULK_LEAP. (Since I can't see anything in "MONSTERSTATE_COMBAT")
    for example:

    case SKULK_LEAP:
    {
    pev.movetype = MOVETYPE_FLY; // change state
    ... your existing code ...
    pev.movetype = MOVETYPE_STEP; // reset state
    }

    self.pev.velocity = g_Engine.v_forward * 2000;
    Isn't gravity around 180 in SC engine, seems like "The Flash/Flash Gordon" speed there.

    Note: Setting MOVETYPE_FLY will probably result in a straight-line trajectory pev to target.
    Adjusting "Gravity", may allow (IDK for sure) for a "curved trajectory" and reducing the "* 2000" speed might give players a chance to "get out of way" (If you want that behaviour/option).

    PPS: How do you get code to appear as "code" on the forums
    (what html tag or button are you using ?)
    Regards
    Wolf-3D

  6. #6
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,426

    Re: Leap/Jump attack problems

    Also just noticed:

    else if( distToEnemy >= 96)

    If the npc finds itself in a wide open area (if the map has one) then jump could be 2048 units or whatever the default "scan/see player range" is.
    Regards
    Wolf-3D

  7. #7
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    117

    Re: Leap/Jump attack problems

    Code button is in advanced mode only ("Go Advanced" next to the post button).

    It seems to work as intended with basevelocity.
    That npc has a jump animation with motion extraction, so the jump is a combination of the motion in the animation and the velocity from script.
    It totally looks as i wanted it now, so i see no reason for changing movetype now or anything else.

    Thanks for the help!

  8. #8
    Still learning wolf-3d's Avatar  
    Tester
    Join Date
    Jan 2011
    Location
    Somewhere Warm.
    Posts
    1,426

    Re: Leap/Jump attack problems

    Ok Great, also look forward to seeing "the Jump NPC" in a map at some point and thanks for the "Code:/Go Advanced" Info.
    It may made some of my posts clearer/easier to understand
    Regards
    Wolf-3D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •