The Daily Click ::. Forums ::. Klik Coding Help ::. One enemy randomly selects another enemy to shoot at on the screen?
 

Post Reply  Post Oekaki 
 

Posted By Message

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
23rd December, 2011 at 14:23:40 -

What I want to do is have an enemy randomly choose another enemy on the screen and shoot something at it (for H2 spoilers I can't really say what this is for but it'll be cool I promise!).

In the past, I've done something like "Look towards direction Group.Enemies" however I don't think it works all that well.

There's an MMF2 option called Pick an Object at Random that I've never used and I'm not sure how it works but is that what I should be using to make something like this happen?

I hope that makes sense, thanks!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

nivram



Registered
  20/07/2006
Points
  171
23rd December, 2011 at 15:53:04 -

Give it a try..

Marv

 
458 MMF2 & CTF 2.5 examples and games

http://www.castles-of-britain.com/mmf2examples.htm

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
23rd December, 2011 at 16:10:13 -

Not enough information...
Are you trying to pick just one Enemy (at random?), and have it target one Enemy at random? Or do you want all Enemies to target a (different?) random Enemy?

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
23rd December, 2011 at 16:19:33 -

What happens is that a particular enemy chooses any other enemy in the room at random, and then shoots (top secrety surprise thing) at it.

There's only going to be one of these particular enemies in any room at a given time, so there's just the one shooter enemy to shoot at another random enemy (not itself)

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
23rd December, 2011 at 16:42:50 -

So either:
* use two qualifiers - one for all enemy objects, and one for all apart from the shooter - and then just pick one of the latter at random (group.enemies -> pick or count -> pick group.enemies at random).
* use a flag to differentiate the Shooter from the other members of the Enemy group.

eg.
+ Start of frame
-> Shooter: Set Flag0 to ON

+ Whenever...
+ Group.Enemy: Flag 0 is OFF
+ Group.Enemy: Pick one at random
-> Shooter: Set Angle to ATan2(Y("Shooter")-Y("Group.Enemy"), X("Group.Enemy")-X("Shooter"))
-> Create Bullet at 0,0 from Shooter
-> Bullet: Set Angle to Angle("Shooter") etc...

+ Always
-> Bullet: <insert normal 360 movement expressions here>

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
23rd December, 2011 at 18:50:15 -

That's great, thanks Sketchy I'll try that over the weekend

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
26th December, 2011 at 12:42:54 -

It works except that the shooter always chooses the same enemy to shoot at. I tested it a bunch of times and it's always the same target enemy (out of a possible 2 of them, not including the shooter which has the flag set to 'on' like you said.)

I'll keep working on this though!

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th December, 2011 at 14:50:45 -

Sorry, my bad.
Looks like you probably have to store the target position temporarily, or just use a second qualifier.


// The complicated method
(Group.Enemies contains all enemies including the Shooter object)

+ Start of frame
-> Shooter: Set Flag0 to ON

+ Whenever...
+ Group.Enemies: Flag0 is OFF
+ Group.Enemies: Pick one at random
-> Set TargetX to X("Group.Enemies")
-> Set TargetY to Y("Group.Enemies")

+ Whenever...
-> Shooter: Set Angle to ATan2(Y( "Shooter" )-TargetY, TargetX-X( "Shooter" ))
-> etc...



// The simple method
(Group.Bad contains all enemy objects except for the Shooter object)

+ Whenever...
+ Group.Bad: Pick one at random
-> Shooter: Set Angle to ATan2(Y( "Shooter" )-Y("Group.Bad"), X("Group.Bad")-X( "Shooter" ))
-> etc...


 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
3rd January, 2012 at 16:20:58 -

Well, after everything I tried didn't work I was able to eventually get it to by doing an "enemy target" variable on the shooter and a bunch of comparisons and etc. for the # of enemy objects in the room where the enemy target variable changes and some 'always look in the direction of' stuff.

Took longer than I thought, but who cares? The results are very good and what I was looking to accomplish to make for a more challenging game

THANKS SKETCHY!

(New Devlog Post)
http://www.create-games.com/project.asp?id=1679&view=news&fid=4857

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!
   

Post Reply



 



Advertisement

Worth A Click