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:
Player Melee Actor: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 Pawn: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 }
As my code can attest, I'm pretty new to programming, so I welcome any advice.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); }



Reply With Quote


Bookmarks