Jump to content
  • entries
    945
  • comments
    5,899
  • views
    930,190

One Last Thing


Josh

9,020 views

 Share

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->SetMass(10);
enemy->SetPhysicsMode(Entity::CharacterPhysics);
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.)

enemy->SetHook(Entity::DrawHook,UpdateEnemyAnimation)

void UpdateEnemyAnimation(Entity* entity)
{
   entity->SetAnimationFrame(Time::GetCurrent()/100.0);
}

  • Upvote 3
 Share

32 Comments


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.

 

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.

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.

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.

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.

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.

Link to comment

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

×
×
  • Create New...