Page 6 of 6 FirstFirst ... 456
Results 201 to 217 of 217
  1. #201
    MSgt. Shooter Person
    Join Date
    Sep 2011
    Posts
    57

    Default

    Please can someone post the missing code? I'm just trying to crack the AI writing and from the posts I see all my questions are answered here (but i cannot understand them without the reference code).
    Otherwise I will just have to ask all the questions that has been answered before all over again ://

    If you cannot (or you do not want to) share xnasorcerer code, maybe someone will be able to answer the most important thing for me:

    1. What is the proper place for a state of patroling (state should be in inside the npcAIController? or NpcPawn?)
    2. How can I gather Path Nodes from level (placed in the world, not spawned by script) and point specific NpcPawn to follow them while in specific state (the one from point 1)
    3. How can I ask my NPCPawn to play a certain animation from his anim tree (im using the standard base male animset / animtree from UDK)

    Thanks in advance, if by chance anyone would want to help me I promise after I'm done I'll write a good tutorial for future noobies like me :]

  2. #202

    Default

    ok so no xnasorcerer script and no tutorials where to go

  3. #203
    Prisoner 849
    Join Date
    Jan 2010
    Posts
    903

    Default

    Quote Originally Posted by [Talanar] View Post
    Please can someone post the missing code? I'm just trying to crack the AI writing and from the posts I see all my questions are answered here (but i cannot understand them without the reference code).
    Otherwise I will just have to ask all the questions that has been answered before all over again ://

    If you cannot (or you do not want to) share xnasorcerer code, maybe someone will be able to answer the most important thing for me:

    1. What is the proper place for a state of patroling (state should be in inside the npcAIController? or NpcPawn?)
    2. How can I gather Path Nodes from level (placed in the world, not spawned by script) and point specific NpcPawn to follow them while in specific state (the one from point 1)
    3. How can I ask my NPCPawn to play a certain animation from his anim tree (im using the standard base male animset / animtree from UDK)

    Thanks in advance, if by chance anyone would want to help me I promise after I'm done I'll write a good tutorial for future noobies like me :]
    1.the aicontroller is the only place for that.
    2. you could try a foreach loop of AllActors of the pathnode class.
    3. not sure, but probably PlayAnimation() if that can be accessed.

  4. #204
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    186

    Default

    I apologize for this but where is the AI code from XNASorcerer located at? I have no luck finding it at all...

  5. #205

    Default

    Yea, if any has XNAsorcerer's code that'd probably be really useful for people who have found this thread via search and are still having trouble...

  6. #206
    MSgt. Shooter Person
    Join Date
    Dec 2010
    Posts
    56

    Default

    I too am looking for something extremely similar to this. I want to have a bot that randomly patrols using navmesh and then goes to path nodes once he sees the player.

  7. #207
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    186

    Default

    Is the code to this still online, if so could someone point me to it?

  8. #208
    MSgt. Shooter Person
    Join Date
    Dec 2009
    Location
    College Park, Georgia
    Posts
    355
    Gamer IDs

    Gamertag: Tanx100 PSN ID: HawkX4

    Default

    Not sure why xnasorcerer deleted all of his posts, but luckily I found this.

    Pawn Class
    Code:
    class Badguy1 extends UTPawn
    	placeable;
    
    // members for the custom mesh
    var SkeletalMesh defaultMesh;
    //var MaterialInterface defaultMaterial0;
    var AnimTree defaultAnimTree;
    var array<AnimSet> defaultAnimSet;
    var AnimNodeSequence defaultAnimSeq;
    var PhysicsAsset defaultPhysicsAsset;
    
    var Badguy1Controller MyController;
    
    var float Speed;
    
    var SkeletalMeshComponent MyMesh;
    var bool bplayed;
    var Name AnimSetName;
    var AnimNodeSequence MyAnimPlayControl;
    
    var bool AttAcking;
    
    var () array<NavigationPoint> MyNavigationPoints;
    
    defaultproperties
    {
        Speed=80
    	AnimSetName="ATTACK"
    	AttAcking=false
    
    	defaultMesh=SkeletalMesh'TDDUP_Animations.Animations.Character'
    	defaultAnimTree=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	defaultAnimSet(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    	defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.mesh.SK_CH_Corrupt_Male_Physics'
    
    
    	Begin Object Name=WPawnSkeletalMeshComponent
    		bOwnerNoSee=false
    		CastShadow=true
    
    		//CollideActors=TRUE
    		BlockRigidBody=true
    		BlockActors=true
    		BlockZeroExtent=true
    		//BlockNonZeroExtent=true
    
    		bAllowApproximateOcclusion=true
    		bForceDirectLightMap=true
    		bUsePrecomputedShadows=false
    		LightEnvironment=MyLightEnvironment
    		//Scale=0.5
    		SkeletalMesh=SkeletalMesh'TDDUP_Animations.Animations.Character'
            AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    	End Object
    
    	mesh = WPawnSkeletalMeshComponent
    
    	Begin Object Name=CollisionCylinder
    		CollisionRadius=+0041.000000
    		CollisionHeight=+0044.000000
    		BlockZeroExtent=false
    	End Object
    	CylinderComponent=CollisionCylinder
    	CollisionComponent=CollisionCylinder
    
    	bCollideActors=true
    	bPushesRigidBodies=true
    	bStatic=False
    	bMovable=True
    
    	bAvoidLedges=true
    	bStopAtLedges=true
    
    	LedgeCheckThreshold=0.5f
    	
    }
    
    simulated function PostBeginPlay()
    {
    	super.PostBeginPlay();
    	//if (Controller == none)
    	//	SpawnDefaultController();
    	SetPhysics(PHYS_Walking);
    	if (MyController == none)
    	{
    		MyController = Spawn(class'Badguy1Controller', self);
    		MyController.SetPawn(self);		
    	}
    
        //I am not using this
    	//MyAnimPlayControl = AnimNodeSequence(MyMesh.Animations.FindAnimNode('AnimAttack'));
    }
    
    function SetAttacking(bool atacar)
    {
    	AttAcking = atacar;
    }
    
    
    
    simulated event Tick(float DeltaTime)
    {
    	local UTPawn gv;
    
    	super.Tick(DeltaTime);
    	//MyController.Tick(DeltaTime);
    
    	
    	//foreach CollidingActors(class'UTPawn', gv, 200) 
    	foreach VisibleCollidingActors(class'UTPawn', gv, 100)
    	{
    		if(AttAcking && gv != none)
    		{
    			if(gv.Name == 'MyPawn_0' && gv.Health > 0)
    			{
    				//Worldinfo.Game.Broadcast(self, "Colliding with player : " @ gv.Name);
    				gv.Health -= 1;
    				gv.IsInPain();
    			}
    		}
    	}
    }
    
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    	Mesh.SetSkeletalMesh(defaultMesh);
    	//Mesh.SetMaterial(0,defaultMaterial0);
    	Mesh.SetPhysicsAsset(defaultPhysicsAsset);
    	Mesh.AnimSets=defaultAnimSet;
    	Mesh.SetAnimTreeTemplate(defaultAnimTree);
    
    }
    Controller Class
    Code:
    class Badguy1Controller extends AIController;
    
    var Badguy1 MyBadguy1Pawn;
    var Pawn thePlayer;
    var Actor theNoiseMaker;
    var Vector noisePos;
    
    var () array<NavigationPoint> MyNavigationPoints;
    var NavigationPoint MyNextNavigationPoint;
    
    var int actual_node;
    var int last_node;
    
    var float perceptionDistance;
    var float hearingDistance;
    var float attackDistance;
    var int attackDamage;
    
    var float distanceToPlayer;
    var float distanceToTargetNodeNearPlayer;
    
    var Name AnimSetName;
    
    var bool AttAcking;
    var bool followingPath;
    var bool noiseHeard;
    var Float IdleInterval;
    
    defaultproperties
    {
        attackDistance = 50
        attackDamage = 10
        perceptionDistance = 1000
    
    	AnimSetName ="ATTACK"
    	actual_node = 0
    	last_node = 0
    	followingPath = true
    	IdleInterval = 2.5f
    
    }
    
    function SetPawn(Badguy1 NewPawn)
    {
        MyBadguy1Pawn = NewPawn;
    	Possess(MyBadguy1Pawn, false);
    	MyNavigationPoints = MyBadguy1Pawn.MyNavigationPoints;
    }
    
    function Possess(Pawn aPawn, bool bVehicleTransition)
    {
        if (aPawn.bDeleteMe)
    	{
    		`Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
    		 ScriptTrace();
    		 GotoState('Dead');
        }
    	else
    	{
    		Super.Possess(aPawn, bVehicleTransition);
    		Pawn.SetMovementPhysics();
    		
    		if (Pawn.Physics == PHYS_Walking)
    		{
    			Pawn.SetPhysics(PHYS_Falling);
    	    }
        }
    }
    
    function Tick(Float Delta)
    {
    	//if(IsInState('Attack'))
    	//{	
    
    	//}
    	
    }
    
    state Idle
    {
    
        event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
                GotoState('Chaseplayer');
            }
        }
    
    Begin:
        Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");
    
    	Pawn.Acceleration = vect(0,0,0);
    	MyBadguy1Pawn.SetAttacking(false);
    
    	Sleep(IdleInterval);
    
    	//Worldinfo.Game.Broadcast(self, "!!!!!!!  Going to FollowPath  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    	followingPath = true;
    	actual_node = last_node;
    	GotoState('FollowPath');
    
    }
    
    state Chaseplayer
    {
      Begin:
    	
    	MyBadguy1Pawn.SetAttacking(false);
        Pawn.Acceleration = vect(0,0,1);
    	
        while (Pawn != none && thePlayer.Health > 0)
        {
    		Worldinfo.Game.Broadcast(self, "I can see you!!");
    		
    		if (ActorReachable(thePlayer))
    		{
    			distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
    			if (distanceToPlayer < attackDistance)
    			{
    				GotoState('Attack');
    				break;
    			}
    			else //if(distanceToPlayer < 300)
    			{
    				MoveToward(thePlayer, thePlayer, 20.0f);
    				if(Pawn.ReachedDestination(thePlayer))
    				{
    					GotoState('Attack');
    					break;
    				}
    			}
    		}
    		else
    		{
    			MoveTarget = FindPathToward(thePlayer,,perceptionDistance + (perceptionDistance/2));
    			if (MoveTarget != none)
    			{
    				//Worldinfo.Game.Broadcast(self, "Moving toward Player");
    
    				distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    				if (distanceToPlayer < 100)
    					MoveToward(MoveTarget, thePlayer, 20.0f);
    				else
    					MoveToward(MoveTarget, MoveTarget, 20.0f);	
    		
    				//MoveToward(MoveTarget, MoveTarget);
    			}
    			else
    			{
    				GotoState('Idle');
    				break;
    			}		
    		}
    
    		Sleep(1);
        }
    }
    
    state Attack
    {
     Begin:
    	Pawn.Acceleration = vect(0,0,0);
    	MyBadguy1Pawn.SetAttacking(true);
    	while(true && thePlayer.Health > 0)
    	{   
    		//Worldinfo.Game.Broadcast(self, "Attacking Player");
    
    		distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer > attackDistance * 2)
            { 
    			MyBadguy1Pawn.SetAttacking(false);
                GotoState('Chaseplayer');
    			break;
            }
    		Sleep(1);
    	}
    	MyBadguy1Pawn.SetAttacking(false);
    }
    
    
    auto state FollowPath
    {
    	event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
    			noiseHeard = true;
    			followingPath = false;
                GotoState('Chaseplayer');
            }
        }
    
     Begin:
    
    	while(followingPath)
    	{
    		MoveTarget = MyNavigationPoints[actual_node];
    		
    		if(Pawn.ReachedDestination(MoveTarget))
    		{
    			//WorldInfo.Game.Broadcast(self, "Encontrei o node");
    			actual_node++;
    			
    			if (actual_node >= MyNavigationPoints.Length)
    			{
    				actual_node = 0;
    			}
    			last_node = actual_node;
    			
    			MoveTarget = MyNavigationPoints[actual_node];
    		}	
    
    		if (ActorReachable(MoveTarget)) 
    		{
    			//distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    			//if (distanceToPlayer < perceptionDistance / 3)
    			//	MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);	
    			//else
    				MoveToward(MoveTarget, MoveTarget);	
    		}
    		else
    		{
    			MoveTarget = FindPathToward(MyNavigationPoints[actual_node]);
    			if (MoveTarget != none)
    			{
    				
    				//SetRotation(RInterpTo(Rotation,Rotator(MoveTarget.Location),Delta,90000,true));
    				
    				MoveToward(MoveTarget, MoveTarget);
    			}
    		}
    
    		Sleep(1);
    	}
    }
    Franklin Iheanacho - Unrealscript Programmer/3D Environmental Artist

    Renegade X - http://www.renegade-x.com/
    Army Men III - http://armymen3.com/
    Neotl Empire - http://www.youtube.com/user/HawkX4

  9. #209
    MSgt. Shooter Person
    Join Date
    Jun 2011
    Posts
    186

    Default

    Wow thank you so much for this!!!

  10. #210
    MSgt. Shooter Person
    Join Date
    Dec 2009
    Location
    College Park, Georgia
    Posts
    355
    Gamer IDs

    Gamertag: Tanx100 PSN ID: HawkX4

    Default

    No problem. You could also try Mougli's Tutorials for the Sandbox AI.

    AI Tutorial - http://www.moug-portfolio.info/index.php?page=ai-pawns
    Franklin Iheanacho - Unrealscript Programmer/3D Environmental Artist

    Renegade X - http://www.renegade-x.com/
    Army Men III - http://armymen3.com/
    Neotl Empire - http://www.youtube.com/user/HawkX4

  11. #211

    Default

    Quote Originally Posted by Gmax5 View Post
    No problem. You could also try Mougli's Tutorials for the Sandbox AI.

    AI Tutorial - http://www.moug-portfolio.info/index.php?page=ai-pawns
    Thats a great find, but I'm having a slight problem with one line at the moment,
    Code:
    AnimTreeTemplate=AnimTree'SandboxContent.Animations.AT_CH_Human'
    I can see its refering to Mougli's custom content (which I don't have) and I'm wishing to change the "SandboxContent" to something default in the UDK, everything else I changed to default UDK.

  12. #212
    MSgt. Shooter Person
    Join Date
    Feb 2012
    Posts
    265

    Default

    Quote Originally Posted by Cassiden View Post
    Thats a great find, but I'm having a slight problem with one line at the moment,
    Code:
    AnimTreeTemplate=AnimTree'SandboxContent.Animations.AT_CH_Human'
    I can see its refering to Mougli's custom content (which I don't have) and I'm wishing to change the "SandboxContent" to something default in the UDK, everything else I changed to default UDK.
    Find the WPawnSkeletalMeshComponent in UTPawn, it has the "default" AnimTree assigned.

  13. #213

    Default

    I've been playing around with XNAsorcerer's code and I've come into a little bit of a snag, the bot is invisible. It doe's move around and does the "I can see you" and "!! IDLE !!" and the collsion box does work.
    Code:
    class Badguy1 extends UDKPawn
    	placeable;
    
    // members for the custom mesh
    var SkeletalMesh defaultMesh;
    //var MaterialInterface defaultMaterial0;
    var AnimTree defaultAnimTree;
    var array<AnimSet> defaultAnimSet;
    var AnimNodeSequence defaultAnimSeq;
    var PhysicsAsset defaultPhysicsAsset;
    
    var Badguy1Controller MyController;
    
    var float Speed;
    
    var SkeletalMeshComponent MyMesh;
    var bool bplayed;
    var Name AnimSetName;
    var AnimNodeSequence MyAnimPlayControl;
    
    var bool AttAcking;
    
    var () array<NavigationPoint> MyNavigationPoints;
    
    simulated function PostBeginPlay()
    {
    	super.PostBeginPlay();
    	//if (Controller == none)
    	//	SpawnDefaultController();
    	SetPhysics(PHYS_Walking);
    	if (MyController == none)
    	{
    		MyController = Spawn(class'Badguy1Controller', self);
    		MyController.SetPawn(self);		
    	}
    
        //I am not using this
    	//MyAnimPlayControl = AnimNodeSequence(MyMesh.Animations.FindAnimNode('AnimAttack'));
    }
    
    function SetAttacking(bool atacar)
    {
    	AttAcking = atacar;
    }
    
    function AddDefaultInventory()
    {
        InvManager.CreateInventory(class'UTWeap_ShockRifle');
    }
    
    simulated event Tick(float DeltaTime)
    {
    	local UTPawn gv;
    
    	super.Tick(DeltaTime);
    	//MyController.Tick(DeltaTime);
    
    	
    	//foreach CollidingActors(class'UTPawn', gv, 200) 
    	foreach VisibleCollidingActors(class'UTPawn', gv, 100)
    	{
    		if(AttAcking && gv != none)
    		{
    			if(gv.Name == 'MyPawn_0' && gv.Health > 0)
    			{
    				//Worldinfo.Game.Broadcast(self, "Colliding with player : " @ gv.Name);
    				gv.Health -= 1;
    				gv.IsInPain();
    			}
    		}
    	}
    }
    
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    	Mesh.SetSkeletalMesh(defaultMesh);
    	//Mesh.SetMaterial(0,defaultMaterial0);
    	Mesh.SetPhysicsAsset(defaultPhysicsAsset);
    	Mesh.AnimSets=defaultAnimSet;
    	Mesh.SetAnimTreeTemplate(defaultAnimTree);
    
    }
    
    defaultproperties
    {
        Speed=80
    	AnimSetName="ATTACK"
    	AttAcking=true
    
    	defaultMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    	defaultAnimTree=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	defaultAnimSet(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    	defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.mesh.SK_CH_Corrupt_Male_Physics'
    
    	Begin Object Class=SkeletalMeshComponent Name=WPawnSkeletalMeshComponent
    		bOwnerNoSee=false
    		CastShadow=true
    
    		//CollideActors=TRUE
    		BlockRigidBody=true
    		BlockActors=true
    		BlockZeroExtent=true
    		//BlockNonZeroExtent=true
    
    		bAllowApproximateOcclusion=true
    		bForceDirectLightMap=true
    		bUsePrecomputedShadows=false
    		//LightEnvironment=MyLightEnvironment
    		//Scale=0.5
    		SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		HiddenGame=FALSE
    		HiddenEditor=FALSE
    	End Object
    
    	mesh=WPawnSkeletalMeshComponent
    
    	Begin Object Name=CollisionCylinder
    		CollisionRadius=+0041.000000
    		CollisionHeight=+0044.000000
    		BlockZeroExtent=false
    	End Object
    	CylinderComponent=CollisionCylinder
    	CollisionComponent=CollisionCylinder
    
    	bCollideActors=true
    	bPushesRigidBodies=true
    	bStatic=False
    	bMovable=True
    
    	bAvoidLedges=true
    	bStopAtLedges=true
    
    	LedgeCheckThreshold=0.5f
    
    }
    I suspect I've done something rather stupid thats easy to spot by someone who has more experience then I

  14. #214
    Boomshot
    Join Date
    Aug 2011
    Posts
    2,365

    Default

    If you're overriding the existing skeletal mesh component, then remove "class=SkeletalMeshComponent" from the Begin Object declaration.

    If its a separate component, then add "Components.Add(WPawnSkeletalMeshComponent)" after the End Object closing statement.

    Though for that to work correctly you'd need to rename the new component, so I suspect it's the first option. I'd have thought the compiler would catch that error.

  15. #215

    Default

    Huzzah the "Components.Add(WPawnSkeletalMeshComponent)" line worked the bot now walks along path nodes I've told to walk along and spots and follows the player. Now just to get it so the player can shoot it and shoot back.
    Update: I've got the bot now being able to be hit, killed and drop the shock rifle. Now I just need to get it so the gun is in the bots hands and use the gun.

    I've been trying to get the bots to use the UT weapons, but to no success. This is the AI controller that I'm currently using:
    Code:
    class Badguy1Controller extends AIController;
    
    var Badguy1 MyBadguy1;
    var Pawn thePlayer;
    var Actor theNoiseMaker;
    var Vector noisePos;
    
    var () array<NavigationPoint> MyNavigationPoints;
    var NavigationPoint MyNextNavigationPoint;
    
    var int actual_node;
    var int last_node;
    
    var float perceptionDistance;
    var float hearingDistance;
    var float attackDistance;
    var int attackDamage;
    
    var float distanceToPlayer;
    var float distanceToTargetNodeNearPlayer;
    
    var Name AnimSetName;
    
    var bool AttAcking;
    var bool followingPath;
    var bool noiseHeard;
    var Float IdleInterval;
    
    function SetPawn(Badguy1 NewPawn)
    {
        MyBadguy1 = NewPawn;
    	Possess(MyBadguy1, false);
    	MyNavigationPoints = MyBadguy1.MyNavigationPoints;
    }
    
    function Possess(Pawn aPawn, bool bVehicleTransition)
    {
        if (aPawn.bDeleteMe)
    	{
    		`Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
    		 ScriptTrace();
    		 GotoState('Dead');
        }
    	else
    	{
    		Super.Possess(aPawn, bVehicleTransition);
    		Pawn.SetMovementPhysics();
    		
    		if (Pawn.Physics == PHYS_Walking)
    		{
    			Pawn.SetPhysics(PHYS_Falling);
    	    }
        }
    }
    
    function Tick(Float Delta)
    {
    	//if(IsInState('Attack'))
    	//{	
    
    	//}
    	
    }
    
    state Idle
    {
    
        event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
                GotoState('Chaseplayer');
            }
        }
    
    Begin:
        Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");
    
    	Pawn.Acceleration = vect(0,0,0);
    	MyBadguy1.SetAttacking(false);
    
    	Sleep(IdleInterval);
    
    	//Worldinfo.Game.Broadcast(self, "!!!!!!!  Going to FollowPath  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    	followingPath = true;
    	actual_node = last_node;
    	GotoState('FollowPath');
    
    }
    
    state Chaseplayer
    {
      Begin:
    	
    	MyBadguy1.SetAttacking(false);
        Pawn.Acceleration = vect(0,0,1);
    	
        while (Pawn != none && thePlayer.Health > 0)
        {
    		Worldinfo.Game.Broadcast(self, "I can see you!!");
    		
    		if (ActorReachable(thePlayer))
    		{
    			distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
    			if (distanceToPlayer < attackDistance)
    			{
    				GotoState('Attack');
    				break;
    			}
    			else //if(distanceToPlayer < 300)
    			{
    				MoveToward(thePlayer, thePlayer, 20.0f);
    				if(Pawn.ReachedDestination(thePlayer))
    				{
    					GotoState('Attack');
    					break;
    				}
    			}
    		}
    		else
    		{
    			MoveTarget = FindPathToward(thePlayer,,perceptionDistance + (perceptionDistance/2));
    			if (MoveTarget != none)
    			{
    				//Worldinfo.Game.Broadcast(self, "Moving toward Player");
    
    				distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    				if (distanceToPlayer < 100)
    					MoveToward(MoveTarget, thePlayer, 20.0f);
    				else
    					MoveToward(MoveTarget, MoveTarget, 20.0f);	
    		
    				//MoveToward(MoveTarget, MoveTarget);
    			}
    			else
    			{
    				GotoState('Idle');
    				break;
    			}		
    		}
    
    		Sleep(1);
        }
    }
    
    state Attack
    {
     Begin:
    	Pawn.Acceleration = vect(0,0,0);
    	MyBadguy1.SetAttacking(true);
    	while(true && thePlayer.Health > 0)
    	{   
    		//Worldinfo.Game.Broadcast(self, "Attacking Player");
    
    		distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer > attackDistance * 2)
            { 
    			MyBadguy1.SetAttacking(false);
                GotoState('Chaseplayer');
    			break;
            }
    		Sleep(1);
    	}
    	MyBadguy1.SetAttacking(false);
    }
    
    
    auto state FollowPath
    {
    	event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
    			noiseHeard = true;
    			followingPath = false;
                GotoState('Chaseplayer');
            }
        }
    
     Begin:
    
    	while(followingPath)
    	{
    		MoveTarget = MyNavigationPoints[actual_node];
    		
    		if(Pawn.ReachedDestination(MoveTarget))
    		{
    			//WorldInfo.Game.Broadcast(self, "Encontrei o node");
    			actual_node++;
    			
    			if (actual_node >= MyNavigationPoints.Length)
    			{
    				actual_node = 0;
    			}
    			last_node = actual_node;
    			
    			MoveTarget = MyNavigationPoints[actual_node];
    		}	
    
    		if (ActorReachable(MoveTarget)) 
    		{
    			//distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    			//if (distanceToPlayer < perceptionDistance / 3)
    			//	MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);	
    			//else
    				MoveToward(MoveTarget, MoveTarget);	
    		}
    		else
    		{
    			MoveTarget = FindPathToward(MyNavigationPoints[actual_node]);
    			if (MoveTarget != none)
    			{
    				
    				//SetRotation(RInterpTo(Rotation,Rotator(MoveTarget.Location),Delta,90000,true));
    				
    				MoveToward(MoveTarget, MoveTarget);
    			}
    		}
    
    		Sleep(1);
    	}
    }
    
    defaultproperties
    {
        attackDistance = 50
        attackDamage = 10
        perceptionDistance = 1000
    
    	AnimSetName ="ATTACK"
    	actual_node = 0
    	last_node = 0
    	followingPath = true
    	IdleInterval = 2.5f
    
    }
    I've added the following to the bot.uc
    Code:
    var() class<UTWeapon> WeaponClass;
    This is allowing me choose what weapon the bot has in the same way you can with a weapon locker, but I'm not 100% sure if it works or not until I can get the bots to use guns and shoot the player with said gun.
    Last edited by Cassiden; 06-20-2012 at 12:27 AM.

  16. #216

    Default

    I've spent the last 3-ish days trying the get BotAI script to carry and use a gun against the player,
    The Pawn
    Code:
    class Badguy1 extends UDKPawn
    	placeable;
    
    // members for the custom mesh
    var SkeletalMesh defaultMesh;
    //var MaterialInterface defaultMaterial0;
    var AnimTree defaultAnimTree;
    var array<AnimSet> defaultAnimSet;
    var AnimNodeSequence defaultAnimSeq;
    var PhysicsAsset defaultPhysicsAsset;
    
    var Badguy1Controller MyController;
    
    var float Speed;
    
    var SkeletalMeshComponent MyMesh;
    var bool bplayed;
    var Name AnimSetName;
    var AnimNodeSequence MyAnimPlayControl;
    
    var () array<NavigationPoint> MyNavigationPoints;
    
    function AddDefaultInventory()
    {
        local Weapon newWeapon;
        newWeapon = Spawn(class'UTGameContent.UTWeap_ShockRifle',,,self.Location);
        if (newWeapon != none)
        {
            newWeapon.GiveTo(Controller.Pawn);
            newWeapon.bCanThrow = false; //Doesn't allow default weapon to be thrown
            Controller.ClientSwitchToBestWeapon();
        }
    }
    
    
    
    simulated function PostBeginPlay()
    {
    	super.PostBeginPlay();
    	//if (Controller == none)
    	//	SpawnDefaultController();
    	SetPhysics(PHYS_Walking);
    	if (MyController == none)
    	{
    		MyController = Spawn(class'Badguy1Controller', self);
    		MyController.SetPawn(self);		
    	}
    	 
            AddDefaultInventory();
    
        //I am not using this
    	//MyAnimPlayControl = AnimNodeSequence(MyMesh.Animations.FindAnimNode('AnimAttack'));
    }
    
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    	Mesh.SetSkeletalMesh(defaultMesh);
    	//Mesh.SetMaterial(0,defaultMaterial0);
    	Mesh.SetPhysicsAsset(defaultPhysicsAsset);
    	Mesh.AnimSets=defaultAnimSet;
    	Mesh.SetAnimTreeTemplate(defaultAnimTree);
    
    }
    
    defaultproperties
    {
    
    	//AnimSetName="ATTACK"
    	//AttAcking=true
    
    	defaultMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    	defaultAnimTree=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	defaultAnimSet(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    	defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.mesh.SK_CH_Corrupt_Male_Physics'
    
    	Begin Object Class=SkeletalMeshComponent Name=WPawnSkeletalMeshComponent
    		bOwnerNoSee=false
    		CastShadow=true
    
    		CollideActors=TRUE
    		BlockRigidBody=true
    		BlockActors=true
    		BlockZeroExtent=true
    		//BlockNonZeroExtent=true
    
    		bAllowApproximateOcclusion=true
    		bForceDirectLightMap=true
    		bUsePrecomputedShadows=false
    		//LightEnvironment=MyLightEnvironment
    		//Scale=0.5
    		SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		HiddenGame=FALSE
    		HiddenEditor=FALSE
    	End Object
    
            Components.Add(WPawnSkeletalMeshComponent)
    	mesh=WPawnSkeletalMeshComponent
    
    	Begin Object Name=CollisionCylinder
    		CollisionRadius=+0041.000000
    		CollisionHeight=+0044.000000
    		BlockZeroExtent=false
    	End Object
    	CylinderComponent=CollisionCylinder
    	CollisionComponent=CollisionCylinder
    
            //Set movement parameters
            bJumpCapable=false
            bCanJump=false
            GroundSpeed=250.0
            MaxStepHeight=50.0
    
            bAvoidLedges=true
            bStopAtLedges=true
    
    	LedgeCheckThreshold=0.5f
    
    }
    The Controller
    Code:
    class Badguy1Controller extends AIController;
    
    var Badguy1 MyBadguy1;
    var Pawn thePlayer;
    var Actor theNoiseMaker;
    var Vector noisePos;
    
    var () array<NavigationPoint> MyNavigationPoints;
    var NavigationPoint MyNextNavigationPoint;
    
    var int actual_node;
    var int last_node;
    
    var float perceptionDistance;
    var float hearingDistance;
    var float attackDistance;
    
    var float distanceToPlayer;
    var float distanceToTargetNodeNearPlayer;
    
    var Name AnimSetName;
    
    var bool followingPath;
    var bool noiseHeard;
    var Float IdleInterval;
    
    function SetPawn(Badguy1 NewPawn)
    {
        MyBadguy1 = NewPawn;
    	Possess(MyBadguy1, false);
    	MyNavigationPoints = MyBadguy1.MyNavigationPoints;
    }
    
    function Possess(Pawn aPawn, bool bVehicleTransition)
    {
        if (aPawn.bDeleteMe)
    	{
    		`Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
    		 ScriptTrace();
    		 GotoState('Dead');
        }
    	else
    	{
    		Super.Possess(aPawn, bVehicleTransition);
    		Pawn.SetMovementPhysics();
    		
    		if (Pawn.Physics == PHYS_Walking)
    		{
    			Pawn.SetPhysics(PHYS_Falling);
    	    }
        }
    }
    
    function Tick(Float Delta)
    {
    	//if(IsInState('Attack'))
    	//{	
    
    	//}
    	
    }
    
    state Idle
    {
    
        event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
                GotoState('Chaseplayer');
            }
        }
    
    Begin:
        Worldinfo.Game.Broadcast(self, "!!!!!!!  idle  !!!!!!!!");
    
    	Pawn.Acceleration = vect(0,0,0);
    	//MyBadguy1.SetAttacking(false);
    
    	Sleep(IdleInterval);
    
    	//Worldinfo.Game.Broadcast(self, "!!!!!!!  Going to FollowPath  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    	followingPath = true;
    	actual_node = last_node;
    	GotoState('FollowPath');
    
    }
    
    state Chaseplayer
    {
    
      Begin:
    	
    	//MyBadguy1.SetAttacking(false);
        Pawn.Acceleration = vect(0,0,1);
    	
        while (Pawn != none && thePlayer.Health > 0)
        {
    		Worldinfo.Game.Broadcast(self, "I can see you!!");
    		
    		if (ActorReachable(thePlayer))
    		{
    			distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
    			if (distanceToPlayer < attackDistance)
    			{
    				GotoState('Attack');
    				break;
    			}
    			else //if(distanceToPlayer < 300)
    			{
    				MoveToward(thePlayer, thePlayer, 20.0f);
    				if(Pawn.ReachedDestination(thePlayer))
    				{
    					GotoState('Attack');
    					break;
    				}
    			}
    		}
    		else
    		{
    			MoveTarget = FindPathToward(thePlayer,,perceptionDistance + (perceptionDistance/2));
    			if (MoveTarget != none)
    			{
    				//Worldinfo.Game.Broadcast(self, "Moving toward Player");
    
    				distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    				if (distanceToPlayer < 100)
    					MoveToward(MoveTarget, thePlayer, 20.0f);
    				else
    					MoveToward(MoveTarget, MoveTarget, 20.0f);	
    		
    				//MoveToward(MoveTarget, MoveTarget);
    			}
    			else
    			{
    				GotoState('Idle');
    				break;
    			}		
    		}
    
    		Sleep(1);
        }
    }
    
    state Shoot
    {
    ignores SeePlayer;
    Begin:
            thePlayer = GetALocalPlayerController().Pawn;
            Pawn.ZeroMovementVariables();
            Sleep(1);
            Pawn.StartFire(0);
            Pawn.StopFire(0);
            
            //If player is too far away go back to Followpath
            distanceToPlayer = VSize( Pawn.location - thePlayer.location );
            
            if( distanceToPlayer > 200 )
            {
                    GotoState('FollowPath');
            }
            goto 'Begin';
    }
    
    auto state FollowPath
    {
    	event SeePlayer(Pawn SeenPlayer)
    	{
    	    thePlayer = SeenPlayer;
            distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
            if (distanceToPlayer < perceptionDistance)
            { 
            	//Worldinfo.Game.Broadcast(self, "I can see you!!");
    			noiseHeard = true;
    			followingPath = false;
                GotoState('Chaseplayer');
            }
        }
    
     Begin:
    
    	while(followingPath)
    	{
    		MoveTarget = MyNavigationPoints[actual_node];
    		
    		if(Pawn.ReachedDestination(MoveTarget))
    		{
    			//WorldInfo.Game.Broadcast(self, "Encontrei o node");
    			actual_node++;
    			
    			if (actual_node >= MyNavigationPoints.Length)
    			{
    				actual_node = 0;
    			}
    			last_node = actual_node;
    			
    			MoveTarget = MyNavigationPoints[actual_node];
    		}	
    
    		if (ActorReachable(MoveTarget)) 
    		{
    			//distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
    			//if (distanceToPlayer < perceptionDistance / 3)
    			//	MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);	
    			//else
    				MoveToward(MoveTarget, MoveTarget);	
    		}
    		else
    		{
    			MoveTarget = FindPathToward(MyNavigationPoints[actual_node]);
    			if (MoveTarget != none)
    			{
    				
    				//SetRotation(RInterpTo(Rotation,Rotator(MoveTarget.Location),Delta,90000,true));
    				
    				MoveToward(MoveTarget, MoveTarget);
    			}
    		}
    
    		Sleep(1);
    	}
    }
    
    defaultproperties
    {
        //attackDistance = 50
        //attackDamage = 10
        perceptionDistance = 1000
    
    	//AnimSetName ="ATTACK"
    	actual_node = 0
    	last_node = 0
    	followingPath = true
    	IdleInterval = 2.5f
    
    }
    I've been basing the code around XNAsorcerer's code as I like the pathfinding and the ability of telling the bots where to go. I'm sure I have missed something since I'm still learning UScript, so any help would be greatly appreciated.

  17. #217
    MSgt. Shooter Person
    Join Date
    Jul 2012
    Location
    USA
    Posts
    203

    Default

    Why must you delete all your useful tutorials?!


 
Page 6 of 6 FirstFirst ... 456

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.