Data Driven Actor Behaviours

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Data Driven Actor Behaviours

      So a friend and I have been working on an engine to get more experience working on games. We got our engine to the point where we made a really basic and junky pong game, we did it because we realized that there were alot of design flaws in our engine that we had not thought about, so decided to try and make something even remotely interesting out of it before we stopped and actually designed what we need out of an engine.

      One thing that I felt clueless about, was how games define individual actor behaviors. For instance in our tiny game, we had a 6 walls that formed a container, ok easy enough, we loaded it in from an xml level file, they don't do anything either than interact via the physics system with collisions. Next we had the paddles, this was easy, as the behavior of these objects were controlled through a game view, whether it is a Human, AI, or Remote view.

      The thing that I couldn't figure out, is how do I make actors, that are not attached to a game view, behave differently. A good example is our 'Pong' ball, it does not need to be attached to a AI view, as it is simply an object that moves with the paddles.

      I hard coded the movement as it was the only actor in our demo that needed movement without a View attached. This seems sloppy as I don't think (maybe I'm wrong), that you need to hold things like the balls movement vector directly in the game logic class. This required me to also hold a pointer to the ball directly in the game logic. On every logic update, the ball's movement vector was hard coded to apply force to the ball's rigid body. I also added a listener in the Logic class to reverse the recieved collision normal and change the balls vector upon a collision.

      I think if I am understanding correctly, with this component based Actor architecture I should be using processes. I'm just not sure how to go about it, how would I define in say, a Lua Script, to make one specific instance of a ball move each frame in the direction of it's movement vector?
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • RE: Data Driven Actor Behaviours

      For a simple ball, you could probably just set it up with the appropriate physics parameters and it'd be fine. A ball bouncing around shouldn't require any new code; it should be pure physics.

      Other actors that have non-physics based movement should be controlled with a process, as you suggested. This would likely be something you set up in script through the ScriptComponent. The ScriptComponent has a constructor element in the XML that contains code to be executed. For an example of this, look at the script component definition in the ai_teapot.xml file:

      Source Code

      1. <BaseScriptComponent>
      2. <ScriptObject constructor="AddEnemy" destructor="RemoveEnemy" />
      3. <ScriptData actorType="Teapot" />
      4. </BaseScriptComponent>


      This will call the AddEnemy() Lua function when an actor of this type is instantiated. AddEnemy() is defined in LevelInit.lua as a pass-through to ActorManager:AddEnemy(). This function does the heavy lifting of instantiating a new enemy object on the script side. There are similar functions for the player, the sphere, etc. This is the pattern you would follow. If you want a special ball with special behavior, you write a custom "constructor" method for it and give it its own override in the level builder tool. This "constructor" is where you would write the code that spawned your update process.

      For example, if I wanted to make a sphere that traveled in a sine wave for 30 seconds before disappearing, I would write a new process subclass. The OnUpdate() function would first check to see if the object was valid (the actor might have been destroyed or something). Then it would do the math to calculate the new position for the actor. Then it would update the actor's position. The second thing I'd write is a new "constructor" function in ActorManager that spawned my new process. That should be all you need. Even better, this whole thing will work with absolutely no C++ code (although you may want the trig functions needed for the sine wave to be in C++ eventually). Having this be a process also decouples it from the object itself. You can have spheres, pyramids, or even teapots use the exact same process if you like.

      -Rez