Results 1 to 6 of 6
  1. #1
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    563
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default Effect only works 10-20% of the time

    I've set this one on the back burner because it was never really a big priority, and I take a look at it every now and then but I just can't figure out the problem. So what the heck, I'm just gonna make a big 'ol post here with a lot of code and see if anyone has any ideas how to solve this.

    The desired effect:
    When the player attacks there is a visible sword-slash graphic that appears before him. It is visible for the exact duration of the portion of the attack that is actually damaging other actors, and then disappears.

    The reality:
    The sword slash only appears some of the time. There is no pattern to when it does or does not, save that most of the time it does not. I might see it appear after five tries or after sixteen. I can stand, I can jump, I can move, I can spam the attack button, I can wait between attacks, there is nothing in my action that determines if it will work or not.
    Curiously, the effect seems to be more/less successful depending upon the level I am testing it in.

    The process:
    When the pawn is spawned it creates a "melee actor" that is attached to itself at a desired offset. The melee actor is a simple static mesh of a rectangular billboard (with a custom collision) with the slash effect on it. This actor is what handles the actual damaging effects on other actors. When spawned the material is set to a "blank" image.
    When the player attacks it triggers a sequence of timers. At the desired moment after the trigger the attached mesh is sent into it's active state where it damages other actors, and it's material is changed to the visible material. A moment later the next trigger sends the mesh into its inactive state, which switches the material back to the blank one.
    I have also tried to make the mesh hidden instead of switching the material, but it has the same effect.

    The code:
    Player Controller:
    Code:
    function AssignSword(PlayerMeleeActor SentActor)
    {
      `log("Assigning Sword to Player Controller...");
      sword = SentActor;
    }
    
    exec function MeleeAttack()
    {
        if(pawn != None && !bPlayerInAttack)
        {
            //wind-up,animation starts (duration: 0.04)
            bPlayerInAttack=true;
            MCPlayerPawn(Pawn).HoldPlayer();
            setTimer(0.4, false, nameof(StopAttack) );
            //Pitch, attack becomes active (duration: 0.01)
            setTimer(0.04, false, nameof(MakeSwordActive) );
    
            //cool-down, attack becomes inactive and animation finishes. (duration: 0.35)
            setTimer(0.05, false, nameof(MakeSwordInert) );
        }
    }
    
    function StopAttack()
    {
        bPlayerInAttack=false;
        MCPawn(Pawn).bIsAttacking =false;
        MCPlayerPawn(pawn).ReleasePlayer();
    }
    
    function MakeSwordActive()
    {
        Sword.gotostate('Active');
    }
    
    function MakeSwordInert()
    {
        Sword.gotostate('Inert');
    }
    Player Melee Actor:
    Code:
    class PlayerMeleeActor extends actor;
    
    var actor Controller;
    var actor OwnerPawn;
    var StaticMeshComponent Mesh;
    var int MeleeAttackDamage;
    var vector AttackMomentum;
    
    function setSwordController(actor SentActor)
    {
     `log("Assigning Controller to Player Melee Actor...");
     Controller = SentActor;
    }
    
    function setOwningPawn(actor SentActor)
    {
     `log("Assigning Pawn to Player Melee Actor...");
     OwnerPawn = SentActor;
    }
    
    
    state active
    {
    
         function BeginState( Name PreviousStateName)
         {
            local Actor HitActor;
            local vector Hitloc;
    
           Mesh.SetMaterial(0,Material'MCUniversal.Effects.SwordSlash');
           //Mesh.SetHidden(false);
           playsound(SoundCue'A_Pickups_Powerups.PowerUps.A_Powerup_Berzerk_PickupCue');
           foreach TouchingActors(class 'actor', HitActor)
           {
                if (HitActor != OwnerPawn)
                {
                    HitActor.TakeDamage(MeleeAttackDamage, Instigator.Controller, HitLoc, AttackMomentum, class'DamageType');
                }
           }
         }
         function EndState( Name NewStateName)
         {
           Mesh.SetMaterial(0,Material'MCUniversal.Effects.SwordSlashBlank');
           //Mesh.SetHidden(true);
         }
         function touch(Actor TouchedActor, PrimitiveComponent OtherComp, vector HitLoc, vector HitNormal )
         {
            if (TouchedActor != OwnerPawn)
            {
                TouchedActor.TakeDamage(MeleeAttackDamage, Instigator.Controller, HitLoc, AttackMomentum, class'DamageType');
            }
         }
         Begin:
          //sleep(0.5);
          //gotostate('Inert');  //from an older version
    }
    
    
    auto state inert
    {
     Begin:
    }
    
    
    defaultproperties
    {
        MeleeAttackDamage=100
    
    	// Add the static mesh component
    	Begin Object Class=StaticMeshComponent Name=MyStaticMeshComponent
    		StaticMesh=StaticMesh'MCUniversal.Effects.BilboardSquare128_64'
    		bOnlyOwnerSee=false
    		CastShadow=false
    		bForceDirectLightMap=true
    		bCastDynamicShadow=false
    		CollideActors=true
    		BlockRigidBody=false
    		Translation=(X=64.0,Y=0.0,Z=16.0)
    		Rotation=(Pitch=0,Yaw=32768,Roll=0)
    	End Object
    	Components.Add(MyStaticMeshComponent)
    	Mesh=MyStaticMeshComponent
    
        CollisionType=COLLIDE_TouchAll
        bCollideActors=true
    
    
    }
    Player Pawn:
    Code:
    function PossessedBy(Controller C, bool bVehicleTransition)
    {
        super.PossessedBy(C, bVehicleTransition);
     	`log("Spawning sword...");
    	Sword = Spawn(class'PlayerMeleeActor');
        Sword.SetBase(Self);
        `log("Preparing assignments...");
        Sword.SetSwordController(controller);
        Sword.SetOwningPawn(self);
        MCPController = MCPlayerController(Controller);
        MCPController.AssignSword(Sword);
        Sword.Mesh.SetMaterial(0,Material'MCUniversal.Effects.SwordSlashBlank');
        //Sword.Mesh.SetHidden(true);
    }
    As my code can attest, I'm pretty new to programming, so I welcome any advice.
    Last edited by marscaleb; 05-16-2012 at 02:01 PM.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  2. #2

  3. #3
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    563
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    Just a static image.
    I change it from one static image to another.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  4. #4
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Probably because of too short time between MakeSwordActive and MakeSwordInert (0.01 sec...) - depend on machine you playing:
    30fps - most of the time will be not rendered, because DeltaTime = 0.03
    100fps - this could be only one Tick - you can't see it...
    above - will be rendered, but still you can't see it...
    Last edited by VendorX; 05-16-2012 at 05:38 PM.

  5. #5
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    563
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    Hmm, if that's the case then I would be able to solve it if I could find a way to make sure that both timers are not called in the same tick.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  6. #6
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    563
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    ...yeah I think that might have been the problem. Also I've been checking my notes and I put in the wrong times for the sword. After fixing that it works much more correctly. I'm also now considering re-writing the code to be handled within the Player Melee Actor using a few things I've learned since I wrote that code originally.

    Thank for the help!
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.