HomeForumsGeneral DiscussionHaving a Better Friend

Tagged: Friend follows and attacks enemy

This topic has 2 voices, contains 4 replies, and was last updated by  Nat Weiss 328 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
July 13, 2012 at 3:56 am #2597

gholmes

How Can I make my character friend not only follow me around, but attach enemies as well?

July 13, 2012 at 7:38 pm #2600

gholmes

Ok so I was able to get a friend to seek and attack me lol but I need him to follow me but attack the enemy…and also for enemies to attack not just me but my friend(s) as well..whats best way to code that AI?

July 16, 2012 at 7:44 pm #2610

Nat Weiss

You’ll need to code a unique subclass of RPGFriend that seeks the player unless an enemy is near. If an enemy is near, then seek and attack it.

Check out the RPGAI subclass. You’ll need to override at least the walk method and maybe the update method too.

July 24, 2012 at 6:57 am #2638

gholmes

Hey Nat so i put this code for a character in the friend code and it works..well the friend attacks me and flees from time to time..lol so how do I edit the self getPlayer to make it attack an enemy? I need to change that getPlayer to something else correct

-(void) walk
{
// only if not attacking
if( ![self isAttacking] )
{
// attack the player unless fleeing
if( [self canAttack:[self getPlayer] ranged:NO] && mood != kMoodFlee )
{
// make noise
[self playSound:@"attack"];

// attack the player
[self attack:[self getPlayer]];
}

// move
else
{
[super walk];
}
}
}

@end

July 26, 2012 at 11:37 pm #2651

Nat Weiss

Yes.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.