Jump to content

One Last Thing



In this blog I'm going to explain the evolution of the entity and physics system in Leadwerks 3.


In Leadwerks Engine 2, physics bodies and character controllers are both separate entity classes. If you want a model to be physically interactive, you parent it to a body entity. If you want a model to walk around with physics, you parent it to a character controller body.


In Leadwerks 3 I decided to give physics properties to all entities. This means all entities can use commands like GetVelocity(), AddForce(), SetMass(), etc. However, since character controllers are quite different, and they involve kind of a big chunk of code, I decided to keep the character controller as a separate entity. To make an enemy or NPC, you would create a character controller entity and then parent an animated model to that entity.


This was simple enough to do in the editor, but it started getting weird when we added scripts. Scripts for animation would need to be added to the child model, because the character controller would not return any animation lengths or the number of sequences. Scripts to control movement, on the other hand, would have to be attached to the parent character controller, for obvious reasons.


Next I tried creating a character controller script that attached to the model itself. This eliminated the extra entity in the hierarchy, and would automatically create a character controller when loaded in the engine, and parent the model to it. I didn't like that this was changing the hierarchy from what the user saw in the editor, and script accessing the character controller would still be based on some wonky assumptions.


Finally, I decided to just give the entity class a physicsmode member. This can be one of two values. By default, it is Entity::RigidBodyPhysics. However, you can set it to Entity::CharacterPhysics and the entity itself will act as a character controller! All the character controller functions are now available in the entity class, so you can just load a model, adjust some settings, and send him on his merry way around town:

Model* enemy = Model::Load("Models/Characters/barbarian.mdl");
enemy->GoToPoint(20,0,0);//model will walk to this position, using AI navigation


Pretty cool, eh? (If you wanted to add animation, you'd just go it like below.)


void UpdateEnemyAnimation(Entity* entity)


Recommended Comments




Even if I used multiple navigation meshes, the agents on differently sized nav meshes would have no awareness of each other, and would not have flocking/avoidance behavior.


Xaitmap has the ability to use different size nav mesh and different unit radius while being able to have awareness of each other.


Share this comment

Link to comment

There's always a tradeoff. In the future we could have three navmeshes for small, medium, and large characters. You would define those sizes in the scene properties, and each entity would just choose one of those three sizes.


Crowd pathing between agents from different navmeshes is a problem, but it might be something I can get Mikko to figure out a solution to. However, that's an area to research in the future.

Share this comment

Link to comment

Controllers are all the same size, due to their use of the navigation mesh and crowd avoidance


I think it can begin to be complicated, specially for games using any type of character heights.

But yes, not all games will have some ceilling problems , specially on outdoor terrain environments like in MMO games for example.

(Just make doors height big enought for all characters to go throught :) )


And im' not sure everyone will need navMesh navigation depending on game type like 2.5 D platform, simple RPG with distance checking and simple pursue mode for ennemies for ennemies, flying games, space games, card game, arcade casual mobile games ... ,

I hope we would be able to disable the NavMesh use ?



Perhaps i don't know a lot about the threads for collision and animation , but i find using separate sthreads and NavMesh can be too much power consuming for mobiles ?

Perhaps, we should attach the capsule collider at initialisation to the character with the good dimensions ?

Another lot more good way would be to have some graphical panel to adjust the capsule collider and its physical properties ?

I doubt people will put the right values by code , and they have to do lot of error and trials before finding the good ones by code.

A graphical tool , allow you to visualize the new Capsule and adjust it directly at the good size values without having to do lot of erros and trials with code !




This new way of character declaration seems restrictive to me specialy if someone just want to use some simple box to box collision betwenn characters.and a simple detect radius/pursue Player routine !


Yes it seems to be a more easy way and more complete character features compared to LE 2.5.

Well, only trying these new commands and using in a game needing them perhaps i wil be more convincend.

Share this comment

Link to comment

Josh - Thanks for the blog. Quick question related to the topic of physics: Is the physics / animation engine included in LE3 capable of higher than usual floating point precision? I believe most engines run at half floating point (16bit). I'd like to be able to build a streamed world up to around 250km2. Apart from a decent culling technique the key limitation is physics sim once you get further than around 2km out from origin at 16bit floating point.


Thanks Josh.

Share this comment

Link to comment

The physics presently run on 32-bit floats, so you can get about 8 km away from the origin before you have problems.


Entity::GetPosition() returns a dVec3 object. That is a three-component vector that uses doubles for each component (64-bit floats). This is not presently implemented, but the syntax is there for future implementation.

Share this comment

Link to comment

I want to compile LE3 as full 64-bit version with 64-bit doubles. However I'm not sure if Newton is available as source code, and if not, then I might need to use Bullet which comes as source code and can use 64-bit doubles also.

Share this comment

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Add a comment...

×   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.

  • Blog Entries

    • By Haydenmango in Snowboarding Development Blog 6
      So I've been researching snowboarding lately to get an idea of what animations and mechanics I need to create for my game.  I have learned lots of interesting things since I've only seen snow once or twice in my entire life and have never even tried snowboarding or any other board sports (skateboarding, surfing, etc.) for that matter.
      Snowboarding tricks are quite interesting as they are mostly derived from skateboarding.  Snowboarding tricks pay homage to their equivalent skating tricks by sharing many concepts and names.  For example basic grabs in snowboarding share the same concepts and names as skateboarding: indy, mute, method, stalefish, nosegrab, and tailgrab.  Something interesting to note is in snowboarding you can grab Tindy or Tailfish but this is considered poor form since these grabs can't be done on a skateboard (due to the board not being attached to the skaters feet) and grabbing these areas is generally something a novice snowboarder does when failing or "half-assing" a normal grab.  Check out this diagram to see how grabs work -
      So, after reading lots of text descriptions for tricks I was still confused by what all these terms meant and how they were actually applied.  So my next step was to look up these tricks actually being done and I found some really cool videos showing off how to do various tricks.  This video in particular is the best reference material I've found as it contains nearly every trick back to back with labeled names and some tweaks -
      Sadly my rigged model doesn't handle leg animations with the snowboard that well so I can't animate as many tricks as I want to.  Regardless there will still be around 15 total grab/air tricks in the game.  Now it's time for me to stop procrastinating and start animating!  
    • By jen in jen's Blog 3
      I thought I would share my experience on this; if you're working on Multiplayer, you will need to protect your packets. The solution is simple, let's go through how we can achieve this by implementing what Valve calls "challenge codes". (Some reading on the topic from Valve here: https://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol#Challenge_response).
      Disclaimer: this doesn't cover other security techniques like authoritative server or encryption.
      So, I've worked on Border Recon last year (I think) and I needed a way to protect my server/client packets. There was no need for me to re-invent the wheel, I just had to copy what Valve has had for a  long time - challenge  codes.
      The idea behind challenge codes is similar to Captcha, but not exactly. Think of it like this: for every packet submitted to the server, it must be verified - how? By requiring the client to solve challenges our server provides.
      To implement this we need to have the following:
      A randomised formula in the server i.e.: a = b * c / d + e or a = b / c + d - e, be creative - it can be any combination of basic arithmetic or some fancy logic you like and can be however long as you want - do consider that the longer the formula, the more work your server has to do to make the computation.  Copy the same formula to the client. A random number generator.  So the idea here is:
      (Server) Generate a random number (see 3 above) of which the result would become the challenge code, (Server) run it through our formula and record the result. (Client) And then, we hand over the challenge code to the client to solve (an authentic client would have the same formula implemented in its program as we have on the server). For every packet received from the player, a new challenge code is created (and the player is notified of this change by the server in response). For every other packet, a new challenge code is created. (Client) Every packet sent to the server by the client must have a challenge code and its answer embedded.  (Server receives the packet) Run the challenge code again to our formula and compare the result to the answer embedded on the client's packet. (Server) If the answers are different, reject the packet, no changes to the player's state. The advantage(s) of this strategy in terms of achieving the protection we need to secure our server:
      - For every packet sent, new challenge code is created. Typically, game clients (especially FPS) will update its state in a matter of ms so even if a cheater is successful at sniffing the answer to a challenge code it would be invalidated almost instantaneously. 
      - Lightweight solution. No encryption needed. 
      - The formula to answering the challenge code is embedded to the client, a cheater can de-compile the client and uncover the formula. Luckily, we have other anti-cheat solutions for that; you can implement another anti-cheat solution i.e. checking file checksums to verify the integrity of your game files and more (there are third-party anti cheat solutions out there that you can use to protect your game files).
    • By Josh in Josh's Dev Blog 4
      New commands in Turbo Engine will add better support for multiple monitors. The new Display class lets you iterate through all your monitors:
      for (int n = 0; n < CountDisplays(); ++n) { auto display = GetDisplay(n); Print(display->GetPosition()); //monitor XY coordinates Print(display->GetSize()); //monitor size Print(display->GetScale()); //DPI scaling } The CreateWindow() function now takes a parameter for the monitor to create the window on / relative to.
      auto display = GetDisplay(0); Vec2 scale = display->GetScale(); auto window = CreateWindow(display, "My Game", 0, 0, 1280.0 * scale.x, 720.0 * scale.y, WINDOW_TITLEBAR | WINDOW_RESIZABLE); The WINDOW_CENTER style can be used to center the window on one display.
      You can use GetDisplay(DISPLAY_PRIMARY) to retrieve the main display. This will be the same as GetDisplay(0) on systems with only one monitor.
  • Create New...