Jump to content

Chris Paulson

Members
  • Posts

    134
  • Joined

  • Last visited

Posts posted by Chris Paulson

  1. Sorry Lumooja forgot to give you credits. Yes it has a old version of gamelib that I used to get myself started when moving from blitz to c++. I hacked a lot though to to fit my own needs and preferences.

     

    Lines of sight: - Can AI enemy see player checks

  2. File Name: myproject.zip

    File Submitter: Chris Paulson

    File Submitted: 11 Mar 2010

    File Category: C/C++ Code

     

    Hi,

     

    a few more people have asked for my uptodate code including the IK animation, so here it is.

     

    Warning, it's all WIP, messy and unfinished and has it's pants down around it's ankles. If it's a help great, if not tough. Sorry for size of file, it's tricky to cut down without loosing too much.

     

    Thanks to Pixel for the player controller.

    Thanks to Tyler for math code.

     

    Included stuff:-

     

    recast nav mesh

    Behaviour trees (alive)

    Basic AI

    Steering

    Line of sight stuff

    IK animation

    animation definitions loaded from XML

    Blend tree's (WIP)

    Player gun animation

    Scene loading

    Gun/Bullet code

    Maths stuff

     

    Click here to download this file

  3. Then I would have to use a really huge model which is my skydome?

     

    No, all you have to do is have a sphere big enough to cover the camera. It's an illusion with the sky dome as you place it in the background world.

     

    So you have: -

     

    background - for sky dome

    normal - for all other rendering

    foreground - for transparency

  4. http://www.leadwerks.com/wiki/index.php?title=Entities

     

    Get
    EntityCulled
    
       * C: int EntityCulled( TEntity entity, TEntity camera )
       * C++: bool Entity::IsCulled( const Camera& cam ) const
       * BlitzMax: EntityCulled%( entity:TEntity, camera:TCamera )
       * Lua: entity:Culled( camera )
       * Pascal: function EntityCulled ( entity:THandle; camera:THandle ): Integer; 
    
       Returns 0 if the entity is visible from the specified camera, else 1 is returned. 
    

     

     

    You could try EntityCulled but last time I tried to use it didn't work as expected. You may have to do your own field of view maths like line of sight maths then do foreachentityAABB.

  5. I like the fun feeling of that car game. Real cars (except Smart) are boring because they break when you want to have some fun.

     

    I can't believe you've said that and your a Fin aren't you - the gods of driving real cars.

    Go straight to youtube now and watch your country men driving real cars, and repent.

  6. Thought I'd supply code anyway because I'm away from the forum for a few days.

     

    Code snipit: -

    float mapSize = 1024;

    float x;

    float z;

    float mapHalfSize = 512;

    float height;

    for(x = -mapHalfSize; x<mapHalfSize - 1; x++)

    {

    for(z = -mapHalfSize; z<mapHalfSize - 1; z++)

    {

    height = TerrainElevation( terrain, x, z);

    if ((height != 0) || ((x>=minx && x<=maxx) && (z>=minz && z <= maxz)))

    {

    minx = __min(minx, x);

    minz = __min(minz, z);

    maxx = __max(maxx, x);

    maxz = __max(maxz, z);

    //br

    height = TerrainElevation( terrain, (float)x+1, (float)z);

    .

    .

    .

    // Start making plane for terrain square

     

     

    It uses the height and min/max frig to cope with different size of terrains.

  7. Use TerrainElevation.

     

    Raycasts are expensive I would get the TerrainElevation, unless you want to cope with models as well which would require you to do raycasts.

     

    I could supply example code if you can't find any.

  8. I have very specific ideas for a game. However I never mention it because I don't want to be yet another indie game forum dreamer. Until I have a very extensive game engine in place I shall not start making a game.

     

    The forums are full of - I'm going to make a game like Crysis, but better - oh yeah, dream on. This often comes from people who don't even know how to do the basics.

  9. Just got to try some of your bullet hit effect emitters, very nice effects. Maybe you could set a material type in editor and the load the sound and emitter effects based on that. Sorry not criticizing very nice effect though.

     

    If that was at me, I've already done this so sounds etc are stored against the entity key and are used when hit.

  10. I do raycasts with my stuff. When I find a hit I apply a body force to the object hit.

     

    For bigger things like missles etc I might use bodies but I'm not onto that bit yet.

     

    My C++ code: -

     

    #include "gun/include/bullet.h"
    #include "gun/include/bulletHit.h"
    
    #define DEBUG_BULLET
    
    Bullet::Bullet( TVec3 pos, TVec3 dir, TScene *scene, float speed, int life ) : m_force( 100 )
    {
    m_scene = scene;
    m_position = pos;
    m_origin = pos;
    m_life = life;
    m_direction = dir;
    m_speed = speed;
    
    if (!g_bulletEmitterMaterial)
    {
    	g_bulletEmitterMaterial = LoadMaterial("abstract::dust.mat");
    }
    
    HookUpdateEvent(m_scene->updateEvent);
    #ifdef DEBUG_BULLET
    HookRenderEvent(m_scene->renderEvent);
    #endif
    }
    
    Bullet::~Bullet()
    {
    UnhookUpdateEvent( m_scene->updateEvent );
    UnhookRenderEvent( m_scene->renderEvent );
    }
    
    void Bullet::moveBullet()
    {
    m_position.X += m_direction.X*m_speed;
    m_position.Y += m_direction.Y*m_speed;
    m_position.Z += m_direction.Z*m_speed;
    }
    
    void Bullet::Render( float gameLoopTime)
    {
    #ifdef DEBUG_BULLET
    if (m_life)
    	SetColor( Vec4(1,0,0,1) ); // red
    else
    	SetColor( Vec4(1,1,1,1) ); // red
    TVec3 nextPos = Vec3( m_position.X+m_direction.X*m_speed, m_position.Y+m_direction.Y*m_speed, m_position.Z+m_direction.Z*m_speed);
    tdDrawText( m_scene->cam, m_position, "1");
    tdDraw( m_scene->cam, m_position, nextPos );
    tdDrawText( m_scene->cam, nextPos, "2");
    #endif
    }
    
    void Bullet::Update(float gameLoopTime)
    {
    TPick pick;
    
    m_life--;
    if (m_life<=0)
    {
    	//delete (this);
    	return;
    }
    
    moveBullet();
    
    // Look speed metres ahead
    TVec3 nextPos = Vec3( m_position.X+m_direction.X*m_speed, m_position.Y+m_direction.Y*m_speed, m_position.Z+m_direction.Z*m_speed);
    if(LinePick(&pick, m_position, nextPos,0.0,0))
    {
    	builtHitForce( pick );		
    	bulletHitEffect( pick );
    
    	// Create a decal
    	if(pick.surface)
    	{
    		// Add decal if less than 20 metres away
    		/* if(PointDistance(Vec3(pick.X,pick.Y,pick.Z), m_origin) < 20)
    			createBulletDecal( pick, decal ) */
    	}
    	//delete this;
    	m_life = 0;
    	return;
    }
    
    }
    
    void Bullet::builtHitForce( TPick& pick )
    {
    TBody body;
    
    body = GetMeshModel( pick.entity );
    if(body)
    {
    	AddBodyForceAtPoint( body, Vec3(m_direction.X * m_force, m_direction.Y*m_force, m_direction.Z*m_force), Vec3(pick.X,pick.Y,pick.Z) );
    //		SendEntityMessage( topParent(pick.entity), "bullethit", body, 0 );
    	TEntity e = pick.entity;
    	BulletHit *hit = new BulletHit;
    	hit->m_direction = m_direction;
    	hit->m_force = m_force;
    	hit->m_origin = m_origin;
    	hit->m_speed = m_speed;
    	hit->m_pick = pick;
    	while (e)
    	{
    		SendEntityMessage( e, "bullethit", (byte*)hit, 0 );
    		e = GetParent(e);
    	}
    }
    }
    
    void Bullet::bulletHitEffect( TPick &pick )
    {
    TEmitter emitter;
    TWorld world = CurrentWorld();
    
    //loadBulletSounds			
    //If Not emittermaterial emittermaterial=LoadMaterial("abstract::dust.mat")
    SetWorld(m_scene->foregroundworld);
    
    //Richochet emitter
    emitter = CreateEmitter(20, 500, Vec3(0,0,1), 1);
    PositionEntity( emitter, Vec3(pick.X,pick.Y,pick.Z),1 );
    AlignToVector( emitter, Vec3(pick.NX, pick.NY, pick.NZ) );
    PaintEntity( emitter, g_bulletEmitterMaterial );
    SetEmitterVelocity( emitter, Vec3(0,0,3), Vec3(1,1,0) );
    SetEmitterAcceleration( emitter, Vec3(0,-9.8,0) );
    
    //Dust emitter
    emitter = CreateEmitter(10,2000,Vec3(0,0,1),1);
    PositionEntity( emitter, Vec3(pick.X,pick.Y,pick.Z),1 );
    AlignToVector( emitter, Vec3(pick.NX, pick.NY, pick.NZ) );
    PaintEntity( emitter, g_bulletEmitterMaterial );
    SetEmitterVelocity( emitter,Vec3(0,0,0.2),Vec3(0.1,0.1,0) );
    SetEmitterRadius( emitter, 0.25, 0.25 );
    EntityColor( emitter,Vec4(1,1,1,0.1) );
    SetEmitterRotationSpeed( emitter,0.1 );
    
    //Impact sound
    //bulletimpactsound.EmitNPCSound( "bullet", "bullet1", emitter )
    
    SetWorld( world );
    }
    
    

  11. String pulling:-

     

    Imagine a 2d square grid and you did a path from one point to another, the path would have zig zags in if you used the centre of each square. String pulling smooths out the zig zags.

     

    To help with this, imagine a string tied to a peg and it works its way between lots of other pegs in a loose zig zag way. Now imagine pulling the string so the string is tight against all the pegs. Ta da - string pulling.

  12. Hi,

     

    I know I like a sound like a stuck record....

     

    but recast has the A* algorithm in it so this is already done. I've also written a version that worked with my own abandoned navmesh stuff which is in blitzmax. Along with a A* algorithm you usally need a string pulling algorithm, which again is in recast and I've also wrote in blitz.

     

    If you want all the info on navmesh's A* etc read this blog

    http://digestingduck.blogspot.com/

     

    it will have all you'll ever want to know.

     

    Or/and read this PDF:-

     

    https://8655380626601746424-a-1802744773732722657-s-sites.googlegroups.com/site/recastnavigation/MikkoMononen_RecastSlides.pdf?attachauth=ANoY7co69z1vjPcvn42QIdX2cYY6w5Qp9HYA8pZiMXS7sWSGoe--OONRdNsxY8F9UUIFFHf2HUBKaYOtxGrfWN6EboojcXsXjnxVyFF-bm2wHBe4tHsq_wYbEYudxkhsiDgEYHQ7biqhOAlawYp6hMP9bwawtKkAw2Qy-gXWs32P0Iym3dkL3TM4ebWiGynr2OU7n1bh6ws1c3xt2ABTT3mQXm94_z0IE8a07kiLoQV4z6_SnZFLLOY%3D&attredirects=0

  13. Oh sweet. Where is that? Did you use that pathfinding code that recast uses also? Also from what I can see recast basically works on an obj file that would be your level. So since LE requires gmf files I assume this is a pre game process to calc the nav mesh on the obj file of your level, save it to disk, then read it in again in the game?

     

    After the load scene is done I feed in all the polygon data (verts/tris) from the terrain and models into recast. Like I say look use my code as a leg up, I've done a fair amount of work on it, I beleive Davris has managed to use my code. It also copes with dynamically updating the navmesh with dynamic objects, such as a barrel moving.

     

    I have not yet written the streaming of the static mesh out but I'll do this when I've finished my current project. I beleive the most recent version of recast may already have this in (but my code does work with the latest version yet).

     

    My code should be in the downloads section, "my game.zip". It also has behaviour tree stuff in which is a better way of doing stuff than FSMs. It also has opensteer in for agent steering. The code is messy as it's all WIP - but it is free.

  14. Is the progamming language really that important for performance ?

    I mean, You code in C++ or Lua just the game logic all the rest depend on the engine

    There are so many other bottlenecks in an engine

    On the other hand I wonder wether Lua is suitable for an advanced A.I.

    I already asked this question in an other thread

    I own many AI books, all of them are written in C++

    Can I port their code in Lua ?

    In theory yes, you can code everything just using if..than statement but I dont think it is an easy task

    In other words, in my opinion the choice of the programming language dpende on the complexity of the game logic rather than on performance

     

    There is more to AI then simple "if then" code. For example: -

     

    Cover point analyse for FP shooters..

    Motion graphs (animation)

    Pathfinding graphs

    Etc etc

     

    AI for a descent FP shooter is doing a lot of maths working on a large amount of data. Speed matters! Thats why AAA titles have to run AI in mutiple threads/cell processors etc.

  15. When it comes default with the library it's easier to use it because it's already built in than to make your own waypoints.

     

    I've actually just found the recast library last night and will be taking a look at it over time.

     

     

    I've posted all my code which interfaces with recast. You might not like my code but it will give you a leg up.

×
×
  • Create New...