Jump to content

Controlling the player


Laurens
 Share

Recommended Posts

Hi,

 

Tonight I took a new approach at handling both input and AI and was hoping you guys could give me some feedback on it. I'll explain how it works by using a Pong example.

 

I have a class called Paddle and a class called Controller (not a Leadwerks TController).

 

The Paddle class keeps a reference to the actual TEntity (the paddle model) and a reference to a Controller. Additionally it has an "Update" method.

 

class Paddle
{
public:

Paddle(TVec3 startPosition, Controller *controller);

void Update();

private:

Controller *controller;
};

 

The Controller keeps a TEntity called target and has a virtual method "Update".

 

class Controller
{
public:

void SetTarget(TEntity target);

virtual void Update() = 0;

protected:

TEntity target;
};

 

When the Paddle is constructed, it loads the model and calls the SetTarget method on the supplied Controller passing in the entity it just loaded. Now, every time the "Update" method is called on the Paddle class (from the main loop) it subsequently calls the "Update" method in the Controller class.

 

Then I create a Player class that inherits from Controller and only overrides the "Update" method.

 

class Player : public Controller
{
public:

void Update();
};

 

The "Update" method from the Player class contains code that checks which key is down and calls the appropriate position and commands on the TEntity target.

 

Next I was planning on creating an AI class that overrides the "Update" method and positions the target based on the position of the ball. That way I could basically plug a Controller in any object and have a player or AI control it.

 

So, what do you think? All constructive criticism appreciated!

Link to comment
Share on other sites

I thikn you are planning to extend this approach with adding native path finding and some other application specific AI stuff support. Why do you intend to put a different controller than engine's? Or am I being confused because both things have the same name but a different meaning? I am considering you are speaking about a same type of controller like we have in LE.

Link to comment
Share on other sites

You are being confused with the fact the names are the same :lol:

 

Replace all instances of "Controller" with "PaddleController" or something. I do not intent to code a replacement for Leadwerks's TController.

 

I do intent to extend the functionality of with specific AI algorithms, correct :)

 

Cheers!

Link to comment
Share on other sites

Having specific AI capabilities for a player controller, which interacts with integrated AI capabilities in an engine (like path finding, etc.) would be incredible! I have never seen such an engine and if one would have it, I believe it would start a new age like crysis did.

Link to comment
Share on other sites

That's basically how the player controller works in gamelib. You can steer it with keyboard or movement commands. The zombie AI which is just following waypoints, is using the same TPLayer class as the player, but it's controlled by the computer. The player entity which the player controls, can be changed on the fly to any other player entity too, so you could step into the AI zombie and take over the controls, then your old corpse would stay dead unless you assign it's corpse to the AI engine.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

That can be easily added, since the zombie follows just a vector of waypoints. So an complex AI only needs to place new entries in the waypoint vector, which is very simple in C++. You can also move waypoints on the fly. You can also add your own AI the same way right now, so you don't have to wait until I write some A* class.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

We have made our path finding system almost complete (only few optimizations remained), I think it is not something "simple" as you said. Or may be we are not very capable, I don't know. Something which works flawlessly for the evaluation for 5 nodes may become a nightmare when evaluating a thousand nodes. Anyway, we use the gamelib 0.16 for the time being and I believe it made us gaining speed and time. We will certainly put a thank to you in our game's contributors list.

Link to comment
Share on other sites

You can put "Thanks to the Leadwerks Community for GameLib", as lots of code and ideas in it is donated by different people from the LE community :lol:

I think the video player should be also part of it, but I need to ask Niosop for permission; and Tyler's web browser.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

You could also use the callback functions.

The UpdateCallback will be called once per loop and even delivers you the entity for which the callback is called. I use this approach and have no problems so far.

Due to the fact that the game loop does not know anything about the game entities, you have

to send informaton via messages, but that works fine.

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

You can put "Thanks to the Leadwerks Community for GameLib", as lots of code and ideas in it is donated by different people from the LE community :lol:

I think the video player should be also part of it, but I need to ask Niosop for permission; and Tyler's web browser.

 

Feel free, my code really isn't anything, it's the libraries that do all the work. I got the sound sync'd a lot better last night, I'll post an updated example project later.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...