AI - melee weapons issue

AI have issues with melee weapons.

  • They stand there doing nothing, on closer inspection the weapon switch audio can be heard, constantly looping.

Tried searching for a working example and was unable find one. I found information relating to Attachcomponent() but im not a coder and wouldn’t know where to begin {Controller class ofr AI, or in teh weapon class? ETC}.
I just need the working lines of code because it is not worth losing so much time over.



SEE ATTACHMENTS - SEE INSTRUCTIONS


INSTRUCTIONS:

  • DOWNLOAD ATTACHMENT
  • RENAME __MazeGameWeapons.TXT

TO_________ MazeGameWeapons.RAR

Congratulations, you just learnt how to upload a ZIPPED file on the UDK forums as an attachment - sneaky sneaky :slight_smile:

Help would be appreciated. Chosker ?:slight_smile:

Chosker would be good :slight_smile:

Code can be irritating but there isn’t a quick fix unless you ask specific questions, but yours are too general.

First glance you’ve got 3 problems: sound, attach weapon and AI movement, and I’m guessing that’s only the start.

There are many posts on the Forum that’ll get you up to speed on AI not moving (couple of links below). Even attachweapons and sound. It’s all been asked before. But to repeat: your question is too general -for me to answer- imo, you need someone to write the whole thing for you, or employ someone to do it for you.

Search the forums for posts by Tegleg GeoDav TheAgent to name a few.

http://r3dstar.co.uk/?p=108

had a quick glance at your code and I saw some basic melee weapon classes.
you have to understand that looking at several entire class files like that to understand a problem is something very time consuming. understanding where the issue comes from and isolating it is something you should spend time doing, and once you know what is wrong is where we can help.

it seems you used ryanjon’s unrealscript wizard and got some unrealscript classes for melee weapons. but coming here to ask why someone else’s code doesn’t work in your game won’t get you the help you need, because you’re essentially asking people to fix your code (since you dont seem to understand it yourself)

and your attached files are just that, the weapon classes. the weapon classes have very limited information for the AI to know how to use them, it’s the AI class that does most of the logic.
to begin with, what’s your AI class? and does it work with other (non-melee) weapons?

The code is not specific to ryanjon, it is the same melee code used by many people.
e.g. googled it and found this the same

Also you say this like it is a bad thing, like i stealing without credits - that is not my intention, i have a seperate credits file and the entire game is documented as a development kit. Like if i uploaded my AI code would you say, hey that is the same code used by UDN or in the Unreal CookBook?.. Well yeh, obviously coz im not a coder.
…Believe me, if epic didn’t delete the UT3 forums multiple times and IF my work still existed i would use my own work on the Chainsaw for UT3 - which took ages and does work but is lost in he web…

  • i would also have to code the impact hammer (i.e. use code that works, port it from UT3)… so yeh forgive me using whatever i can get my hands on :slight_smile:

The code can be seen in many different projects but i am unable to find any project with working example of AI using this code.

There is no AI code to use- i uploaded what i have, no idea where i would start, didn’t know i needed AI to be told about this new weapon.

I assume some form of Trace in the AI code has to be added and that the equip and putdown functionsare not working, maybe that is why i get the noise.

The code provided is all the code i have. sorry if it doesn’t actually help. that’s why im stuck

sorry if it sounded that way, my intention was really not meant to say like you’re stealing without credits or anything.
all I’m saying is you’re trying to fix code that you don’t understand, and so you post all that code for us to read and try to understand, which makes your problem too broad and general for us to help you with it

so lets start with some basic info: knowing what your AI class is.
I’m gonna assume you at least have a custom gameinfo class. does it extend UTGame? if so your AI is most likely a UTBot class
if you don’t have a custom gameinfo class you’re most likely just using UTGame, and your AI is most likely a UTBot class
unless you have a different setup, which means your AI is most likely an AIController class

but you missed my other question: does your AI work with other (non-melee) weapons?
and to round it up: does your AI even do anything at all, to begin with?

Found Ryan’s tutorial- Thanks for the heads up.
[spoiler]
/**

- added to my documentation as the "melee weapon tutorial (Player Pawn ONLY)"
[/spoiler]

*AI Just stands like a lemon as they say. Doing nothing. *

  • GameInfo extends from UTGame
  • I have 2 different AI

1 extends UTPawn, This AI can Shoot. The only code it has is to override the FamilyInfo, and im not sure that even works.



//override to do nothing
simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
{
}


My 2nd Pawn extends the UDK pawn. This AI cannot shoot. Is basically does nothing without a controller class
My Controller class for the 2nd pawn is the EOSC controller pawn. It is unable to fire and simply gets very close to the player. I would like it to shoot, but that won’t happen for me.



/****************************************
*
*	EoSC_AIController
*	Thanks to Mougli @ http://www.moug-portfolio.info 
*	for implementation and of course thanks for sharing :)
*
****************************************/
class AIController_EoSC extends GameAIController;
	
var Actor Player;
var() Vector TempDest;
var float PlayerDistance;

// Making sure the Controller has been called and that f. SUPER.POSTBEGINPLAY is THERE :D (took me 3 hrs to reconize that its needed)
simulated event PostBeginPlay()
{
	super.PostBeginPlay();
	`log("AI CONTROLLER HAS BEEN SPAWNED!");
	enable('NotifyBump');
}

// The pawn falls to the ground and will be switched to the default physics.
event Possess(Pawn inPawn, bool bVehicleTransition)
{
    super.Possess(inPawn, bVehicleTransition);
    Pawn.SetMovementPhysics();
}

// Always remain idle if theirs no pawn to follow.
auto state Idle
{

    event SeePlayer (Pawn Seen)
    {
        super.SeePlayer(Seen);
        Player = Seen;
		
		PlayerDistance = VSize( Pawn.Location - Player.location );
		
		// Make sure we're within fire-range.
		if (PlayerDistance &lt; 200 )
		{
			GotoState('Shoot');

		}
		// If not Hunt him down!
		else
		{
			GotoState('Chase');
		}
	}
Begin:

}

/*	Go on a hunt if you see the player.
*	-ToDo:
*	Stop bots from chasing you all the time.
*/
state Chase
{
ignores SeePlayer;

function bool FindNavMeshPath()
	{
		// We need to clear cache
		NavigationHandle.PathConstraintList = none;
		NavigationHandle.PathGoalList = none;

		// Now lets create the constraints.
		class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle, Player );
		class'NavMeshGoal_At'.static.AtActor( NavigationHandle, Player, 32 );

		// Can be uncommented, just here for debug purpose.
		Worldinfo.Game.Broadcast(self, "The goal is:"@Player);
		Worldinfo.Game.Broadcast(self, "Dest Location is:"@GetDestinationPosition());

		// Find Path
		return NavigationHandle.FindPath();
	}

Begin:
GetALocalPlayerController().Pawn;

PlayerDistance = VSize( Pawn.Location - Player.Location );
	if ( PlayerDistance &lt; 200 )
	{
		GotoState('Shoot');
	}
	else if (NavigationHandle.ActorReachable( Player ) )
	{
		FlushPersistentDebugLines();
		MoveToward( Player, Player, 100 );
	}
	else if( FindNavMeshPath() )
	{
		NavigationHandle.SetFinalDestination(Player.location);
		FlushPersistentDebugLines();
		NavigationHandle.DrawPathCache(,TRUE);
	
	if( NavigationHandle.GetNextMoveLocation( TempDest, Pawn.GetCollisionRadius()) )
		{
			// Uncomment the next two lines when shipping, Debug stuff.
			DrawDebugLine(Pawn.Location,TempDest,255,0,0,true);
			DrawDebugSphere(TempDest,16,20,255,0,0,true);
			MoveTo( TempDest, Player );
		}
	}
	else
		{
			GotoState('Idle');
		}
	goto 'Begin';
}

// OMG we're close, shoot him!
state Shoot
{
//ignores SeePlayer;
Begin:
	Player = GetALocalPlayerController().Pawn;
	Pawn.ZeroMovementVariables();
	Sleep(0);
	Pawn.StartFire(1);
	Pawn.StopFire(0);

	PlayerDistance = VSize( Pawn.Location - Player.Location );
	
	// If the player runs away make sure we're follow him rather than shooting all the time.
	if( PlayerDistance &gt; 200 )
	{
		GotoState('Idle');
	}
	goto 'Begin';
}

defaultproperties
{
}



And finally the pawn that actually has the AXE (my melee weapon) equipped is spawned in Kimset -> actor factory -> UTPawn
^^ i only really care about the UTPawn using the AXE

  • It’s skeletal mesh is replaced by overriding the default replication info and FamilyInfo-- all of which is totally irrelevant to using the weapon

Also:
All the AI from Unreal Script book// patrol bot, random bot etc

We’re a small community so I hope Chosker won’t mind me offering something. He may correct my often faulty suggestions :slight_smile: I’m in a similar position, TKBS, my code’s from everywhere and heavily modified during my learning process - to make it do what I want for my game. I was hoping you’d go and learn because I don’t want to get into a tutor thing. My skills are aren’t up to that. Thankfully Chosker arrived.

UTBot code has been helpful. TheAgent released Full Source, no link sry, but it should be around. His monsters move, attack. Bots with guns is something I’m still working on. Like you I extended from UDKBot.

Not sure if you have attached your bot’s weapon yet?

I added my bot weapon, a melee weapon in the bot Pawn code:



function AddDefaultInventory()  
{
	local Weapon newWeapon;

	PPCont=KFZzPPController(Controller);  //<-------- var KFZzPPController PPCont; at the beginning of the bot's code

	newWeapon = Spawn(class'KFZ.MeleeWep',,,self.Location);
	if (newWeapon != none)
	{
	        newWeapon.GiveTo(PPCont.Pawn);
	        newWeapon.bCanThrow = true;
		PPCont.ClientSwitchToBestWeapon();
	}
}

Making the bot shoot, I'll stumble on how UDKBot code does it.  atm it's a melee weapon, the bot has to touch the player anyway.


Getting my bots moving was a tough. You’re using NavMeshes, I’m using PathNodes.

FindPathToward and MoveToward I think work together. I had FindPathToward and they didn’t move. I added moveToward and they began moving. Also Anchor… from memory I read that bots do nothing if there’s no anchor. Anchor being the “From” and route goal being the “To”, or destination, which makes sense. They need to have a From and To.



I cut a fair bit out of State Roaming, like AdjustAround, seePlayer, and so on.  It's important to know that State code is like a separate .uc, within a .uc.  If the bot's in State Roaming, it's stuck in that loop.  To break the bot out of the loop you put in stuff like
example:
---------
  seePlayer() 
  {
    GotoState('attack')  That breaks the roaming loop.  You add other stuff similar in your states to break their loops.  AdjustAround because if they're on a path 'roaming' (using eg: FindGoal(1), -tis below) and they bump into a mesh they need to adjust around it.
  }
----------

cut down roaming:

auto state Roaming
{
	if(Destination == none || Pawn.ReachedDestination(Destination))
	{
		Destination = FindRandomDest();//gets them moving
		FindGoal(1);                     <----------------------------------- calls the function below and gets them moving.  The (1) because it works... I should experiment XD
		DecisionComponent.bTriggered = true;
	}

     //Find a path to the destination and move to the next node in the path  this makes the civs move!!!
     MoveTarget = FindPathToward(Destination);
     if(MoveTarget != None) 
	 {
		MoveToward(MoveTarget);
		AdjustAround(KFZcp);
	 }

     //fire off next decision loop
	sleep(0.5);
	GoToState('Roaming'); //the loop
}




This code's hacked from UTBot: FindInventoryGoal(float BestWeight) and FindSuperPickup(float MaxDist) functions.  I figured the functions told the bots to goto inventory, so I replaced it's inventory goal with a custom pathnode: ZyPathA ZPA
From what I had read I thought that MoveToward wasn't a good command because it said the bot will move in a straight line not using a path, but as I mentioned, without it they don't move at all.  Could be I'm getting muddled and Anchor fits in there instead...

function bool FindGoal(float BestWeight)
{
	local actor BestPath;
	local ZyPathA ZPA;  // UTPickupFactory P
//	local bool bCanDetour;

	if ( (LastSearchTime == WorldInfo.TimeSeconds) && (LastSearchWeight >= BestWeight) )
		return false;

	if ( (KFZGame(WorldInfo.Game) != None) && !KFZGame(WorldInfo.Game).WantsAPlaceToGo(self) )  //WantsAPlaceToGo() is in KFZGame and doesn't do anything atm.
		return false;

	LastSearchTime = WorldInfo.TimeSeconds;
	LastSearchWeight = BestWeight;

	BestPath = FindPathToward(RouteGoal);//FindBestInventoryPath(BestWeight);
	if ( BestPath != None && ZPA !=None )
	{
		MoveTarget = BestPath;
		ZPA = ZyPathA(RouteGoal);
//		`Log("ZPA = ZypathA routeGoal");
		RouteGoal = ZPA;
		FindPathToward(ZPA);
		if ( (ZPA!=None) && (ZPA == Pawn.Anchor) && Pawn.IsOverlapping(ZPA) )
		{
			ZPA.Touch(Pawn, Pawn.Mesh, ZPA.Location, vect(0,0,1));
		}
		if ( (ZPA != None))
		{
				if ( WorldInfo.TimeSeconds - ZPA.LastSeekNoteTime &gt; 30.0 )
				{
					ZPA.LastSeekNoteTime = WorldInfo.TimeSeconds;
//		SendMessage(None, 'LOCATION', 10, None);
//		`Log("SendMessage None LOCATION");
				}
		}
		return true;
	}
	return false;
}


That’s my wip, which is working. There’s other code I haven’t put up, but we’ll see how this thread goes.

I’m hoping Chosker or someone will come in and criticize and make pathing / Navs a bit clearer. But it’s your thread TKBS and we’re helping you out, and I’m always happy learn. And writing it out actually helps.

edit: Compiling errors when you’re writing state code, usually “end of file at end of class;” “function cannot go here.” Usually it’s because you’ve missed either this { or this }

Thanks for the Input Snipe34
sadly the function AddDefaultInventory() , simply means that you are overriding the default inventory, this doesn’t have any effect on the AI using the weapon
I just do this:



//example only, obviously if i put my axe here the pawn still cannot use it
function AddDefaultInventory()
{
	InvManager.CreateInventory(class'UTGameContent.UTWeap_RocketLauncher_Content');
}


  • Works fine
    I do not have a controller variable for the extension of a UTPawn so that line does not help.

All of the NAVPATH and pathnode stuff is irrelevant to me as it is available in both the unreal script book and can be achieved via kismet. I have AI that move. they just cannot use the axe

But i do really appreciate the input.

@Snipe34
I just thought that this code might help you… I code from the perspective of a level designer not a coder.



class PathNode_CUSTOM extends PathNode;
defaultproperties
{
	Begin Object NAME=Sprite
		Sprite=Texture2D'Maze_EditorResources.Textures.Skeleton_Run'
	End Object
}




// PathNode_SKELETON Array
var array<PathNode_SKELETON> WayPoints;

// declare it at the start so you can use it throughout the script
Var int _PathNode_SKELETON;


then declare them in your custom AI controller

By creating a custom pathnode class you can set specific nodes to AI controllers. Custom sprites for each one.
It is simple but it allows for alot less confusion when you have multiple AI.

I use these with PathNodes and patrol bots. 1 for a skeleton, 1 for a spider etc. Navmesh is still the way to go but for areas where pathfinding is not an issue these are cool LD tools to use.

Hey thanks TKBS.

Yep I realize that’s only the ‘attach function,’ ty.

I also began level designing. I think level designers, good level designers, are better game makers/designers because we understand the finer nuances of game play which are important to map construction; the look of maps, advantages, disadvantages, heights, flats, sounds, novelties and many points that win a map or kill it for players. ‘Win or Kill’ reflects on the entire game. Adding little novelties into maps, leads us as game designers to adding unique novelties into actual play. I think we LDs are good go-betweens, I mean that I’ve seen that for many coders, textures and arty stuff are beyond them. Then there’s artists who faint at coding. Level designers need to be able to transition, kismet for example - we’re in between an advantageous place to be. I should’ve guessed you as an LD, you didn’t attack me for my bumbling code, but instead you kinda, hmmmed, and looked it over, and giving me space. :slight_smile:

Below code should make your bot detect your player when he’s in bot range. Then have your bot strike your player.



//KFZp  is my player pawn.
function HitPlayer() // this is code for Bot Pawn
{
	FullBodyAnimSlot.PlayCustomAnim('WackAttack', 1.0, 0.2, 0.2, false, TRUE);
	KFZp.TakeDamage(10, KFZzyborgController(Controller), Location, vect(0,0,0), class'DamageWack');
}


Next get the bot running to your player to hit(wack) him:



Bot's controller:

What it does:
When the player gets into range the bot runs to the player, and touches him, (and faces player as well!) but atm triggering "Worldinfo.Game.Broadcast(self, "Attacking Player");" (a line in the code below).

What it doesn't do.
bot just follows the player, continually triggering "Worldinfo.Game.Broadcast(self, "Attacking Player")

That's as far as I've got with the code.  But it's at the point where the bot can be made to strike (or in my case checkID).  You get your bot to hit by your player by calling your bot pawn to HitPlayer():  The bot Pawn code is called from the Bot Controller in this way:  var YourBotName YBN;  then in the checkID or attack: YBN = YourBotName(Pawn); then, YBN.HitPlayer();

That's how it should go:  The bot gets into player range, next into the players' face, and as such, calls bot pawn HitPlayer().   The bot strikes the player using your Axe strike animation.

state CheckingID  // obviously call it what you want
{

Begin:
	PPawn = KFZzPP(Pawn); //the bot's pawn
	PPawn.Acceleration = vect(0,0,1);
	CheckIDDistance = 10;
	PerceptionDistance = 100;
	PPawn.Disable('NotifyBump'); /// does swfa?
	settimer(10.0, false, 'EnableBumps');///dit -probably sbe in Pawn?
	
	while (PPawn != none && KFZp.Health > 0 && KFZp !=none)
	{
		if (ActorReachable(KFZp) && KFZp != none) // KFZp caveats are needed otherwise when players run fast out of bot range the game crashes.  btw KFZp is referenced in the same way as YourBotName, YBN.
		{
			distanceToPlayer = VSize(KFZp.Location - PPawn.Location);
			if (distanceToPlayer < CheckIDDistance && KFZp !=none)
			{
				GotoState('Attack');
				break;
			}
			else
			{
				MoveToward(KFZp, KFZp, 0.0f);//, 20.0f(default). Is 0.0f DEST offset?)

				if(PPawn.ReachedDestination(KFZp) && KFZp !=none)
				{
//PPawn.PlaySoundID();
					GotoState('Attack');
					break;
				}
			}
		}
		else
		{
			MoveTarget = FindPathToward(KFZp,,perceptionDistance + (perceptionDistance/2));
			if (MoveTarget != none && KFZp !=none)
			{
Worldinfo.Game.Broadcast(self, "Moving towards Player");//HAVEN't seen this yet - (later: seen it once)

				distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
				if (distanceToPlayer < 300)
					MoveToward(MoveTarget, KFZp, 0.0f);		//20
				else
					MoveToward(MoveTarget, MoveTarget, 0.0f);	//20
			}
			else
			{
				Sleep(0.3);
				Goto('Begin');
				break;
			}		
		}
	}
}

state Attack
{
Begin:

	Pawn.Acceleration = vect(0,0,0);
	CheckIDDistance=10; //presuming UTUnits so that 10 = touching, aka bump -Previously I was using bump (in the bot's Pawn).  Bump does work but I haven't found it much use in this process.

	while(KFZp.Health > 0)
	{   
		Worldinfo.Game.Broadcast(self, "Attacking Player");
		distanceToPlayer = VSize(KFZp.Location - Pawn.Location);

	if (distanceToPlayer > CheckIDDistance * 2)
	{
		Sleep(0.3);
		GotoState('CheckingID');
		break;
}}


The above should get your bot detecting, chasing and then attacking your player.

You said you also had a problem sound?

There’s two types: AudioComponents and soundCues. AudioComponents can be turned on and off (so an 'C can loop). A soundCue can loop too but it can’t be turned off(unless the player or bot or whatever dies). The soundCue loop is only setup in the browser, and loop is all it can do. ACs are made to be triggered on / off, off/on, indefinitely, soundCue aren’t.

I can tell you how to write code for an AC if you want, just ask if that’s you meant in an above post.

Thanks for the pathnode hints. I don’t quite understand what you mean. I’m hoping you mean I can get my bot to follow the _PathNode_SKELETON? (and also specific nodes for individual monsters). I’m trying to get my bots to patrol, but no luck using my custom pathnodes. I hope your pathnode approach may be able to do that for me.

But that later, for now you should code your bots to attack you with axes :slight_smile:

@Snipe34
Please try to stay focused on the topic. There is no issue with AI navigation in this thread.

This code may help me



//KFZp  is my player pawn.
function HitPlayer() // this is code for Bot Pawn
{
	/* 
       - not needed for me
        FullBodyAnimSlot.PlayCustomAnim('WackAttack', 1.0, 0.2, 0.2, false, TRUE);
        */
	KFZp.TakeDamage(10, KFZzyborgController(Controller), Location, vect(0,0,0), class'DamageWack');
}


but i need the full code not the function snippet.
I do not know what is declared where, as there is no reference to your AI controller and your pawn, so i cannot change it to mine. The addition of your custom AIController reference simply confuses me more.

I stress that this is a UTPawn issue, which is spawned in kismet and does not have an AI controller overriding.
[video]- YouTube

The issue must be occurring when we access the firing state array (01)(1) as this is when the sound would be called. (Or it is a weapon attach issue as the sound is like the sound of weapon switching)

If i was to try to add you code to mine i would do this:



var pawn MazeSaveGameStatePawn;
	
/*
Snipe34 bot code to enable cause melee damage to player pawn
// this is code for Bot Pawn
*/
function HitPlayer()
{
	local MazeSaveGameStatePawn MSGSP;
	
	
	MSGSP.TakeDamage(10, AIController_EoSC(Controller), Location, vect(0,0,0), class'Axe_Damage');
}


But i already know without compiling that will return a null yellow error message because am using a local variable before assigning it a value-- and because i do not have the mental capacity to understand that stuff i.e.e what the f’ does that mean? . im screwed. lol

Please post any other unrelated pathnode stuff in another thread. With both threads separated it is much better for all, we can then work on combining the custom AI path and navigation stuff to the use of melee weapons (although that was not my intention it would be useful)


Why so many views on this thread and still no solution?

oh, I just read your post… so ‘edit.’

I’ll try really, really, really hard to stay focused. You ask “Why so many views on this thread and still no solution?” Because they know exactly where you’re at. Most will say what I said originally, go and learn some basics of coding first. But I’m learning, so writing and explaining helps me understand wtf I’m doing too.

They are code snippets? No they aren’t. The reason why the code is as it is, is explained. It’s the code required to make your bot attack system work. Read and re-read what I’ve written above, it means something and will help you understand more about code and what’s it doing.

Spawning from kismet, I know nothing about. Try the controller code in your pawn instead. That’s pretty much what UDK does with its UTBot - it extends from an AI controller.

the full attack code… ok, here it is.



var KFZPawn KFZp;  <-references my pawn  This code goes in your pawn.

function SwingArms()
{
	FullBodyAnimSlot.PlayCustomAnim('WackAttack', 1.0, 0.2, 0.2, false, TRUE);   <- you need to have an animation named WackAttack in your bot's anims.
	KFZp.TakeDamage(10, KFZzyborgController(Controller), Location, vect(0,0,0), class'DamageWack');   <your bots plays the anim and gives you damage.
}

you need a damage type called DamageWack.uc, which should extend some from UTDamage, ie: 

class DamageWack extends UTDamageType;

DefaultProperties
{
}


That’s the full code.

The code I dl from your other post ‘Enemies’ says they’re AIControllers but they’re mostly misnamed. Most are pawns (extending UDKPawn). The controller code is: AIController_EoSC, AIContoller_PatrollingNavMeshBot AIController_Wander and Tessa who extends UTBot.

Next question?
edit: by that I mean we’ll need to go over it again, where do you want to start with the ‘going over’?

personally I keep checking back but I can’t really help
all of my AI, Pawn and Weapon code is custom made. I even had to write my own pathfinding code (I don’t use pathnodes or navmesh)
As such, I’m not knowledgeable in UTBot stuff, neither how it handles weapons or pathfinding