The Daily Click ::. Forums ::. Klik Coding Help ::. Follow the leader AI?
 

Post Reply  Post Oekaki 
 

Posted By Message

J.C



Registered
  22/03/2013 05:18:14
Points
  118
16th June, 2014 at 16/06/2014 17:15:38 -

Hello again.

Using the PMO object, I'm trying to create one of those types of platform games where there are two playable characters that you can switch to at will. What I'm a little stuck on is how to program the second playable character to follow the first player (think games like Donkey Kong Country).

 
n/a

J.C



Registered
  22/03/2013 05:18:14
Points
  118
19th June, 2014 at 19/06/2014 18:38:23 -

After some tinkering I've kind of figured it out myself! Turns out all you have to do is set up a counter,
Initial value 1
Min value 1
Max value 3

Since there are 2 playable characters, the numbers indicate which character is currently being controlled. 1 for player 1, 2 for player 2. Number three exists to shift control back to 1.

Basically the code looks like this:

Group P2 Follow player 1
X position of player2 sprite > X(position of P1 collision detector box)+15
User is holding left input key (for P2 PMO object)
X position of player2 sprite < X(position of P1 collision detector box)-15
User is holding right input key (for P2 PMO object)
Always
P2 collision look at (0,0) from P1 collision box

Same goes for the player 1 Follow player 2 group.

Hope that helps for anyone else who is curious to pull this off in their games.



Edited by J.C

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
21st June, 2014 at 21/06/2014 17:50:51 -

Nice idea!
Would work without PMO too!
I'll hog this

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image

J.C



Registered
  22/03/2013 05:18:14
Points
  118
22nd June, 2014 at 22/06/2014 06:56:14 -


Originally Posted by Eternal Man [EE]
Nice idea!
Would work without PMO too!
I'll hog this



Ah, glad I was able to help out! If you would like I could create an example file showing off the code I used for a project.

 
n/a

Eternal Man [EE]

Pitied the FOO

Registered
  18/01/2007
Points
  2955

Game of the Week WinnerHero of TimeLOL SignI am an April Fool
23rd June, 2014 at 23/06/2014 23:32:43 -

Sure!
The more activity on the site the better!

 
Eternal Entertainment's Code'n'Art Man

E_E = All Indie


...actually Ell Endie, but whatever.
Image
Image
   

Post Reply



 



Advertisement

Worth A Click