Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2
1  Game Development / Newbie & Debugging Questions / Re: Get direction of camera (player is looking at) on: 2013-04-04 18:20:51
Yes, you'll need to add the camera's current position to the newly generated x,y,z values to get the destination position for the object you're trying to draw in front of the camera.

Regarding the trig - remember that the X,Y and Z positions are all going to be affected by the current camera pitch.



In the diagram you can see how calculating the X position of the end of a line is directly affected by its angle. The same can be said in 3D. Your X and Z positions, extrapolated from your YAW angle, need to take the current pitch angle as a coefficient, since that too will affect its output.

To be honest, just by using the method described earlier to grab the XYZ position based off of the camera angles is the only code you'll likely need to do this in future, since it seems to be a pretty standard method.

I hope you find this helpful.
2  Game Development / Newbie & Debugging Questions / Re: Get direction of camera (player is looking at) on: 2013-04-04 14:34:04
If you're looking at simply placing an object in front of the camera (regardless of its current rotation / position), you're fortunate in that the code I posted pretty much takes all that leg work out for you.

Just use the resulting newX / newY / newZ values to use as an anchor point for rendering a new cube (series of quads), or a quick and dirty to test it out would be to draw a gluSphere or something like that, which will be quicker.

In LWJGL, you can do it quickly during your render cycle with something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
glLoadIdentity();

// <-- do your camera positioning / rotation stuff here

glPushMatrix();
glTranslatef(newX, newY, newZ);   // move to the point projected in front of the camera

glDisable(GL_TEXTURE_2D);   // turn this off to make sure the un-textured sphere surface will draw correctly

Sphere s = new Sphere();    // not optimal to declare here, but this is just an example!
s.draw(2, 12, 12);              // draw the sphere with a radius of 2, with 12 segments and sections

glEnable(GL_TEXTURE_2D);  // re-enable texturing
glPopMatrix();
3  Game Development / Newbie & Debugging Questions / Re: Variable size calculation on: 2013-04-04 14:26:11
Thanks for this detailed and thorough explanation. I guess I must have forgotten about the inevitable assignment of a pointer to the array's memory address.

Presumably, arrays are contiguous in memory (i.e. only require a single address location and size terminator), so that would assume that the initial assignment pointer will always remain a fixed size (that being the size required to define a memory address) and never grow any larger with different sized arrays.

It's a shame that many languages now adopt the 'everything is an object' methodology - especially with primitive types. I like bytes to stay as bytes and not come with the costly overhead of having additional object requirements clogging up memory space.

Thankfully, with the (relatively) massive amounts of memory available on modern systems, these concerns are fairly trivial. But I can never let that be an excuse for sloppy, wasteful programming practices - especially with fundamental, basic data types!

Thanks again for your helpful explanations!
4  Game Development / Newbie & Debugging Questions / Re: Get direction of camera (player is looking at) on: 2013-04-04 11:41:05
Since you know the current pitch and yaw of the camera, you can use the following calculation to obtain an XYZ position along the camera's view vector (from the perspective of the center of the screen):

1  
2  
3  
4  
5  
6  
7  
double cameraPitchInRadians = Math.toRadians(camera.getCameraPitch());
double cameraYawInRadians = Math.toRadians(camera.getCameraYaw());
float f = (float)Math.cos(cameraPitchInRadians);
         
float newX = distanceFromCameraYouWantToMeasure * f * (float)Math.sin(cameraYawInRadians);
float newZ = distanceFromCameraYouWantToMeasure * f * (float)Math.cos(cameraYawInRadians);
float newY = distanceFromCameraYouWantToMeasure * (float)Math.sin(cameraPitchInRadians);


You then add the 'newX/newY/newZ' positions to the current camera position to obtain the new XYZ position in space as projected from the camera.

If you're doing line-of-sight calculations, you may want to iterate through this calculation a number of times with different 'distance from camera' values until you intersect with (or pass through) an object you want to 'pick' out of the scene.

I hope you find this helpful.
5  Game Development / Newbie & Debugging Questions / Variable size calculation on: 2013-04-04 11:22:45
Just a quickie: when trying to calculate the maximum memory footprint of variables in my class, is this the correct assumption?

1  
2  
3  
4  
5  
6  
7  
8  
// one byte
byte value = 10;    

// 10 bytes maximum? Would this be zero-bytes until an element is initialised with a value?
byte[] values = new byte[10];    

// 10,000 bytes maximum? (9.7kb). Again, do the rules with the above array apply re: initialisation?
byte[][] valuesMany = new byte[100][100];    


Thanks for any advice offered here!
6  Game Development / Newbie & Debugging Questions / Re: Geting XYZ of a point along a line (vector) on: 2013-04-01 21:58:10
I just wanted to drop a final post on to say that the code worked a treat - thank you very much!

I modified my original XYZ projection code with the coefficient cosine / sine angles and everything now behaves as expected, thanks a bundle!
7  Game Development / Newbie & Debugging Questions / Re: Geting XYZ of a point along a line (vector) on: 2013-04-01 16:21:55
Thanks for taking the time to post an example. Yes, it appears I've missed this somewhat obvious factor here, so I'll give your modifications a try and report my findings back here.

Thanks again!
8  Game Development / Newbie & Debugging Questions / Geting XYZ of a point along a line (vector) on: 2013-03-31 13:50:59
I know this may seem like a dumb question, but I'm having some odd problems when trying to calculate the position of a point in space along a vector.

My objective is to grab the XYZ coordinates of a point in space directly in front of the camera with a set distance.

I know the pitch, roll and yaw angles of the camera already, and my existing calculation looks like the following (angles in this example are originally stored as degrees, then converted into radians):

1  
2  
3  
4  
5  
6  
7  
float addX = 5  * (float)Math.sin(Math.toRadians(camera.yaw));
float addZ = 5  * (float)Math.cos(Math.toRadians(camera.yaw));
float addY = 5  * (float)Math.sin(Math.toRadians(camera.pitch));

float newX = camera.x + addX;
float newZ = camera.z + addZ;
float newY = camera.y + addY;


The problem I have is that the new point - which does project in front of the camera as intended - doesn't seem to work along the Y axis correctly. It 'clamps' between the angles of -45° to +45°.

So, rotating the camera around the Y axis (yawing) seems to work great - the point 'fires' off from the camera in the right direction - but the plotting of the point in around the camera's pitch arc is out of whack!

For reference, this code is intended to be used as a line-of-sight calculation for detecting what the player is looking at.

Any help would be greatly appreciated. Thank you!
9  Game Development / Newbie & Debugging Questions / Re: More efficient use of Texture.bind() when rendering terrain patches? on: 2013-03-26 17:24:35
This was really useful, thanks!

I ended up creating three render loops - one for each renderable texture type (one for the sides of the terrain, two for the tops).

Thanks for the tip!
10  Game Development / Newbie & Debugging Questions / More efficient use of Texture.bind() when rendering terrain patches? on: 2013-03-26 12:35:20
Hey peeps!

I'm currently using LWJGL to write a terrain renderer for an upcoming project, and wanted to ask a bit of a newbie question about texture binding and performance.

The Set-Up:
Here's a quick schematic of how my terrain works at present:



I load in a greyscale height map of 64 x 64 pixels, where each pixel represents a terrain quad of a set height. The entire data set is split into 16 patches each containing 16 x 16 (256) individual quads.

The Problem:

At runtime, I scan the entire set of terrain patches (16 in total), and work out which ones are in the view frustum (shown in green in the left part of the diagram, from the perspective of the yellow player marker).

For each of these patches in view, I then cycle through each of its individual quads (i.e. the right portion of the diagram) and render them at the required position. No frustum culling is done on these to minimise the amount of view-calculations I'm doing at run time. All of these objects are rendered as VBOs.

My problem is with texture binding. You'll see that in any single patch of terrain, I might have two (or potentially more) different textures to apply. If it was one texture, I'd just do a Texture.bind() once for each patch (or maybe just once per render cycle, until it needs changing for something else), but when there's more than one I'm starting to wonder about the best way to optimise it.

Would a solution be to map out a list of indices for each unique texture to be rendered in any given patch, then cycle through each one - rendering as I go?

So, each patch could have the following code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
// Index arrays for each unique type of texture
boolean[] texIndex1 = new boolean[16*16];
boolean[] texIndex2 = new boolean[16*16];

protected void resetIndices()
{
    for (int i = 0; i < (16*16); i++) { texIndex1[i] = false; texIndex2[i] = false; }
}

protected void setupIndices()
{
    // N.B. These values will be set during the initial terrain load
   // Obviously there would be 'true' values for all 256 quads, but for now
   // I'm just using 8 as an example!
   texIndex1[14] = true;
    texIndex1[18] = true;
    texIndex1[25] = true;
    texIndex1[29] = true;

    texIndex2[6] = true;
    texIndex2[8] = true;
    texIndex2[11] = true;
    texIndex2[21] = true;
}

protected void renderPatch()
{
    // bind the first texture
   texture1.bind();
    for (int i = 0; i < (16*16); i++)
    {
        if (texIndex1[i])
        {
            // render the quad VBO object
       }
    }

    texture2.bind();
    for (int i = 0; i < (16*16); i++)
    {
        if (texIndex2[i])
        {
            // render the quad VBO object
       }
    }
}


Am I thinking along the right lines here? Or should I simply switch texture bindings when needed?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
for (int i = 0; i < (16*16); i++)
{
    // do we need to use texture 1, but are currently using texture 2?
   if (texIndex1[i] && texActive2)
    {
        texActive2 = false;
        texActive1 = true;
        texture1.bind();
    }

    // do we need to use texture 2, but are currently using texture 1?
   if (texIndex2[i] && texActive1)
    {
        texActive1 = false;
        texActive2 = true;
        texture2.bind();
    }

    // render the quad VBO object
}


If someone could provide some insight into whether my ideas above are along the right lines, I'd be really grateful! I might be doing something dreadfully wrong here!

Thanks!
11  Game Development / Newbie & Debugging Questions / Re: Terrain heightmap generation, can this method be easily replicated? on: 2013-02-21 17:57:47
Most helpful, thank you very much Smiley
12  Game Development / Newbie & Debugging Questions / Re: Terrain heightmap generation, can this method be easily replicated? on: 2013-02-21 16:54:24
Thanks! I found some additional resources on alternative methods, such as Diamond-Square and Brownian surfaces, but Perlin noise did come up.

A quick question, though: Generating a perlin noise map seems simple enough, but how do you treat repeated applications of the noise function (to improve terrain diversity)?

Would you apply the noise in an additive fashion, or with a difference method? I'm guessing a difference method would work best, so doing something like this:

1  
newHeight[x][z] = (float)Math.abs(noise1[x][z] - noise2[x][z]);


Still treading early water on this topic, but I appreciate your suggestions - thanks!
13  Game Development / Newbie & Debugging Questions / Terrain heightmap generation, can this method be easily replicated? on: 2013-02-21 16:19:00
Hey all,

I've been playing around with terrain heightmaps recently, and I can get reasonably decent results by first populating a 2D array with random values, then averaging them out using nearest-neighbour interpolation.

However, it all ends up being a bit too homogenous and 'samey'.

In contrast, when I load in a simple greyscale image from Photoshop (using Render -> Clouds, then Render -> Difference clouds), I get beautiful landscapes, from just this simple image:



Produces:


This is just a simple 2D array, with a constrained minimum and maximum elevation clamp (to which the height values are offset against).

I can't seem to work out which is the most suitable algorithm to produce nicely blended noise as shown in the greyscale image above.

I'd appreciate any insights any of you might have! Thanks!

14  Game Development / Newbie & Debugging Questions / Re: Free-flying camera Y axis movement too fast, is tangent vector calc wrong? on: 2013-02-20 14:10:40
That's perfect! Thanks for your help!
15  Game Development / Newbie & Debugging Questions / Free-flying camera Y axis movement too fast, is tangent vector calc wrong? on: 2013-02-20 11:33:23
Hi All,

I've written a camera class to handle FPS-style movement throughout the game world, but for some reason I don't seem to be traveling the correct distance along the Y axis when pointing in that direction. Here's the code that handles the calculation of 'moving forward' along the current vector:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
protected void moveForward(float distance)
   {
      // track value (for debugging)
     lastMoveForward = distance;
     
      speedX -= (distance * (float)Math.sin(Math.toRadians(yaw)));
      speedZ += (distance * (float)Math.cos(Math.toRadians(yaw)));
       
       if (flyMode) { speedY += distance * (float) Math.tan(Math.toRadians(pitch)); }
   }


Some quick code notes:
yaw: a value between 0-359
pitch: a value clamped between -80 (looking down) and 80 (looking up)
speedX/Y/Z: values that are added to the camera's X, Y and Z positions respectively, then zeroed-out ready for the next tick.

Moving along the X and Z axes (when looking along those axes) works beautifully. The distance travelled is ~4 units per second.

However, when flyMode is switched on (for a free-flying camera), and looking up or down, the distance travelled is vastly different - more like 20-30 units per second.

Am I calculating the speed increment along the Y axis totally wrong? Or maybe a combination of them all?

Many thanks for any help anyone can offer. I'm already learning how tremendously resourceful this community can be : )
16  Game Development / Newbie & Debugging Questions / Re: LWJGL Timing problem on: 2013-02-20 09:48:57
This was a tremendously useful explanation, thank you very much!

I'll have to adjust the code somewhat, in that case, but I'd much rather incur some laggy frames and retain full timing control than suffer the bane of weird movement artifacts when the game slows down.

Once again, your input is much appreciated, thanks!
17  Game Development / Newbie & Debugging Questions / Re: LWJGL Timing problem on: 2013-02-19 17:40:33
Thanks. I guess I'll just have to dig around some more and maybe do some separate tests.

Thanks for taking a look over the code, though.
18  Game Development / Newbie & Debugging Questions / Re: LWJGL Timing problem on: 2013-02-19 17:12:33
Thank you for the reply, but I think you have have misinterpreted how I'm using the speed variable (which is perhaps more to do with me not furthering my example).

After the speed is calculated, it's applied to the current position:

1  
2  
speed = (forwardSpeed * GameLoop.delta) / 1000f;
position.x += speed;


It's essentially the same as your example. I'm aware of the need to adjust the amount of distance you need to travel based on timing, rather than ticks, which is why I feel that my problem is with my calculation of the timing, rather than the method I'm using to apply it.

In a normal run loop, having a movement speed of, say, 10 would produce wildly fast speeds (for my needs, anyway). That's why I use the 1000f modifier - to bring the final value back down to around the 0.xxxx range.

if forwardSpeed is 10, then the following applies:

N.B. Delta in this example is '10'
(10 * GameLoop.delta) / 1000f = 0.1

If the delta was '2' then the following is true:
(10 * GameLoop.delta) / 1000f = 0.02

Therefore, a faster update of '2', rather than '10' should yield a much slower update distance, correct?

19  Game Development / Newbie & Debugging Questions / LWJGL Timing problem on: 2013-02-19 15:19:57
Hey all,

I'm having some issues with the delta-timing in my game engine. I'm basing it from some tutorial code I worked through, but I've found some cases where it's bugging out a bit. Timing seems fine when there's no load on the engine and the framerates are high, but when there's a lot on the screen (during stress testing), the timing goes well out of whack.

For example, a movement along one axis of 1 unit per second somehow ends up as 50 units per second when the game is 'laggy' when under load.

Here's the two key methods. First, the main game loop (N.B. the 'delta' static member of the encompassing class, so I can access it from elsewhere):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
public void start()
   {
      lastFrame = getTime();
      lastFPS = getTime();
      delta = 0;
      gameState = startupState;
           
      // while the game is running we loop round updating and rendering
     while (!Display.isCloseRequested() && !AppWin.ref.isClosedRequested())
      {
         // calculate the frame delta (time elapsed since the last loop iteration)
        int _delta = (int) (getTime() - lastFrame);
         lastFrame = getTime();
         
         delta = _delta;
         
         // clear the display
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
         
         // ensure a constant update speed
        int remainder = delta % 10;
         int step = delta / 10;
         
         // run as many update cycles as we need to catch up to our render timing
        for (int i=0;i<step;i++)
         {
            update(10);
         }
         if (remainder != 0)
         {
            update(remainder);
         }
         
         // render the game
        render(delta);
         
         // refresh the display
        Display.update();
         Display.sync(60);

         // update the current FPS value
        updateFPS();
      }
     
      Display.destroy();
      System.exit(0);
   }


And the timing function:

1  
2  
3  
4  
private long getTime() 
   {
      return (Sys.getTime() * 1000) / Sys.getTimerResolution();
   }


Here's a typical example of how I use this delta value:

1  
2  
3  
// what speed are we moving at, based on the current delta?
// 'forwardSpeed' will be a fixed value, such as 10
speed = (forwardSpeed * GameLoop.delta) / 1000f;


I'm clearly doing something wrong here, otherwise my application of the 'speed' variable would be predictable, regardless of frame rate.

Thanks for any insight anyone can offer Smiley
20  Game Development / Newbie & Debugging Questions / Re: Paying to outsource artwork, anyone had success with this? on: 2012-03-11 16:44:12
Thanks, I'll take a look. Part of the problem is time, as with all things, but perhaps I can use this as a useful resource moving forward.

Thanks for linking this.
21  Game Development / Newbie & Debugging Questions / Paying to outsource artwork, anyone had success with this? on: 2012-03-11 13:59:19
Hi All,

I'm in a bit of a quandry, because I imagine like many people on here, I'm not really tremendously proficient in producing artwork resources for my games. The project I'm currently working on is a type of Roguelike game, but in a more science-fiction setting, rather than the treading over the boards of familiar fantasty tropes.

I've tried to use the deviantART 'Job offers' forum board, but to be honest that has resulted in a massive influx of anthro artists just wanting to show me their anime characters and anthro artwork - despite me being very specific in my posting asking for pixel artists with examples of work in sprite creation and tilesets. It's a nightmare, I feel like I'm chasing round in circles. What's worse is that the odd one or two who've actually been promising suddenly get scared off when they have to sign a commercial license to allow their work to be used for my company's projects. What did they expect?

Is there a better place to try and recruit people for this type of work? I'm never looking for people to work for nothing, and like to make sure outsourced work is paid well, but I'm finding it impossible to locate people for the job. I'm looking for reasonably experienced pixel artists, and those comfortable working within the confines of small dimensions for sprites and suchlike.

Any advice would be really appreciated, I'm at a loose end right now.
22  Game Development / Newbie & Debugging Questions / Re: Calculating RPG damage / defense values on: 2012-03-08 16:36:36
I don't necessarily think 'color pie' syndrome, as humorously exampled earlier, is necessarily bad. My use of the term 'fire resistance' was just as a way of trying to convey the extensibility of this type of system, rather than bolt-in a specific facet from the game.

In reality, there are so many more interesting thing you can do with defensive statistics, but essentially it all boils down to something being able to resist, parry or deflect a portion of the damage received.

Having an RPG where your character can reliably hit with 100% of their strength makes most battles very predictable, difficult or not. I based my own attempts of designing this type of system on existing RPG games where some of the following can be true:

- You can deal a baseline level of damage, which can be affected negatively by a random value, but potentially boosted by a positive one (i.e. a 'critical' hit). This works the same for anything else that can attack, unless modified in such a way as to remove some elements of this.

- Both the player and all attacking / attackable entities in the world have some modicum of defense, meaning that they can resist a portion of your damage. They may also be immune or protected against additional damage modifiers. I'm loathe to use the example now, but this might include things like fire, cold, poison etc.

- There is room for stats to be given to allow a certain 'minimum' or 'unresistable' amount of damage to be inflicted, which negates all forms of defense (for that portion of damage only).

I can't be too far off the accepted model, can I? I appreciate the comments relating to the (obvious) unoriginal nature of this system, but I'm conflicted enough over this already.

Part of me want to create something that people find similar enough to feel comfortable with, and another part of me wants to inject some fresh life into these systems - but without alienating the player and making them feel conflicted over something they'd feel more comfortable with.
23  Game Development / Newbie & Debugging Questions / Calculating RPG damage / defense values on: 2012-03-07 23:44:02
Hi again all,

I'm creating a (very simple) roguelike dungeon crawler, and had a couple of questions regarding the way damage can be calculated when fighting an enemy.

I've got a rough idea of how I want it to work, but I know there are fairly well-set conventions for this sort of thing, so I want to see if I'm on the right track.

Every entity (player and enemy alike) has the following stats:

- Health (how many hit points it has)
- Damage (how much damage it deals as a maximum)
- Defense (how much defense it has against taking damage)

So, for example, the player starts with 100 health, 4 damage, and 5 defense. A weak enemy of equal level may have perhaps 30% or less weaker stats; so a weak enemy might have: 30 health, 1 damage, 2 defense.

When I'm writing in my calculations for attacking, I'm using the following assumptions:

1) Player attacks, so we start by first assuming the attack will initially cause maximum damage of 4.
2) The enemy's defense is used as a mitigating factor for this damage, and is converted to a percentage
3) The weak enemy's defense, as shown above, can now mitigate 2% of the player's maximum damage
4) Because defense isn't guaranteed, a randomisation is run to calculate how much of that defense to use (0 - 2%, in this case)
5) The player's maximum damage value is reduced by this defense value - so if reduced by 2% defense, it results in a damage of 3.92.

Obviously, these numbers are pretty small. But compare this to perhaps later in the game where a player's weapon can deal a maximum of, say, 300 damage. Fighting an enemy with health of 500 and a defense of 40 could potentially have a worst case scenario of your weapon only doing a total of 180 damage (40% of 300).

What I want to know is whether or not this method is sound? It sounds right in my head, and obviously gives me some degree of flexibility to add further damage types if I want to get clever:

- Player's main weapon deals max. of 200 melee damage
- Main weapon also deals 80 fire damage
- Enemy has 0 defense, but 100 fire resist
- Player's main weapon hits for the full 200 damage, but fire resist can reduce that additional damage down to as little as zero.

And so on.

I'd appreciate any thoughts from veterans of these types of game systems.

Thanks!
24  Game Development / Newbie & Debugging Questions / Re: How to work with a big world? EXTENSIVE QUESTIONS on: 2012-03-07 12:03:19
Chunks are 16x16x128, but are stored in region files which contain 32x32 chunks each.
Except it just changed, so now chunks are 16x16x16, and there may be up to 16 chunks in each vertical collumn (so the max height is now 256).

I stand corrected! So, the layout is essentially divided into 4 chunk columns (in each region file), and up to 16 chunk slices in each column of 16x16 within that 32 x 32 region. Thinking logically, that's a better organisational method, since it'd be trivial to view-test the bounding area of a chunk for rendering rather than based on the player's position. So really, unless you're looking into an enormous quarry, you're actually not seeing a whole lot of chunks at runtime.

Anyway, this is veering off the OPs question now, and delving into the intricacies of data management in everyone's favourite brick builder!
25  Game Development / Newbie & Debugging Questions / Re: Precomputed tile paths for pathfinding? on: 2012-03-07 11:58:32
I think there's a degree of complexity on assumption here that isn't necessary for the project I'm working on.

I agree that the inherant problems with pathfinding in a node system where blockages and interruptions are present can be cumbersome and difficult to overcome, but I'm taking an approach that removes most of these problems completely. How?

By stopping the player.

Let's say you want to go from point A to point G, and an appropriate path is calculated. Along the route, say, at tile D, you come across an enemy. In the above examples, people are generally suggesting methods of recaculating the path based on this (possibly new) obstruction and thereby increasing the load on the pathfinder.

However, my aim here is to simply halt the player and cancel out any further movement along that path. It's then up to the player to either deal with the obstacle (fight it) or go somewhere else.

I appreciate this might seem like a dumbed down idea, and certainly one ignominious to the normal practices of pathfinding, but in reality - I'm not looking for a graceful solution where the player's path can anticipate, overcome or circumvent dynamic obstacles. Simply bumping up against the obstacle en-route and stopping is more than sufficient for my needs.

In many ways, there are some benefits there. Clicking inside a room, only to have your player stroll over and bump up (and stop) against the door leading to that room, only serves to reinforce the fact that the player cannot simply 'stroll where they want' using this method. And, in fact, I would also say that as a player I would expect a pathfinding algorithm to at least attempt to take me as far as it possibly can (i.e. the door), leaving me to realise what I need to do to proceed to that area.

Too many times in C&C games I've ordered my units to a position on the map, and they've instead wandered off and wedged themselves next to a cliff - leaving me to wonder if that's actually intentional, and whether there's a blockade I need to deal with to proceed.

In my example above, the pathfinder assumes the player has a clear route to the room, but when the door is encountered, they are stopped. If the door is the only route in, then the pathfinder is actually technically finding the best route to the door, since that's where they'll be stopped, which is actually a desired artefact of this kind of dynamic perception of the local surroundings.

Hmm, that was perhaps a little more verbose than I'd intended. But in summary:

- The player does not need to circumvent dynamic obstacles (e.g. moving enemies), only be stopped by them
- The player will analyse surrounding obstacles during their path traversal
- It is not essential that the player (or in fact any moving enemy) is omniscient enough to predict obstacles before they become so, only that they are seen just before the moment of impact.


I should imagine this simplifies the solution somewhat, as the pathfinding will always take place on the entire walkable surface of the map, and the (carefully selected) obstructions will be dealt with in real-time during the course of the path movement.
26  Game Development / Newbie & Debugging Questions / Re: Precomputed tile paths for pathfinding? on: 2012-03-07 01:14:57
You mentioned, earlier, that you were thinking about how it'd work if it were ported over to a mobile device. To me, that means touch screen controls for the most part.

Correct, that was my intial reason for adding mouse support to the game. Mouse clicks on tiles can be replaced by W,S,A,D movement on PCs, and mouse clicks on enemies to attack, pick up items or such can also be replaced by key presses (or the mouse!). Thus, touch screen capability is retained.

With regard to the static map; I refer to my earlier post regarding the possibility for only slight differences in the walkability of any particular calculated path. Would it be fair to assume that if the path is being traversed one node at a time (after the correct route has been calculated) that it would be fairly trivial to do a quick per-node check to see if the approaching tile is still walkable?

This goes back to my A- > B -> C example, but I think it's still relevant in this instance.

I'm not necessarily backtracking on my decision to go A* on this project; but I think it's worth considering all options in the event that I want to take a little from column A, and a little from column B.
27  Game Development / Newbie & Debugging Questions / Re: How to work with a big world? EXTENSIVE QUESTIONS on: 2012-03-07 01:08:40
I've never seen Minecraft's code, but that's how I would do it.

This behaviour is actually quite easy to see if you install any admin mods that allow you to fly faster than the recommended speed.

Since chunk loading is handled on its own thread, the effect in-game is minmal and mostly unintrusive. However, if you pick a direction and fly very quickly - you'll eventually start seeing chunks loading on-screen. The division between the chunk areas in this instance is very easy to see.

I may be wrong, but I believe the chunk size in Minecraft is 64x64x256 (1,048,576 blocks). Obviously there are easy ways of graphing this data to be more accessible and quicker to load (since they aren't 1.04 million unique blocks), but generally speaking that's still a vast array of data to store - so it should give the OP some idea of the clout possible with modern CPU / rendering techniques.

I do get the impression, however, that the OP needs to be a little more familiar with zoning and other techniques for improving CPU load and render performance. I would never subject a game to 15,000 simultaneous object updates - or in fact 15,000 renderable objects in one pass. You should be using techniquies such as view culling, and zoning out areas where updates shouldn't be happening (as mentioned by another poster).

This is the best place to ask such questions though, just don't be afraid to try out some of these things and make mistakes along the way - that's how we all learn Smiley
28  Game Development / Newbie & Debugging Questions / Re: Precomputed tile paths for pathfinding? on: 2012-03-07 00:55:18
I'm glad you asked. I should imagine the following answer will either (a) further complexify or (b) simplify the solution.

The player starts off in a set location in the new map. They are shrounded by a 'fog of war', so to speak, with a view radius of about 3 tiles. Since there is code in place to uncover the 'fog' tiles when the player is within a certain proximity to them, I haven't needed to implement any further complex view mechanics, since everything inside of the 'fog' area is ignored.

Please ignore my horrible graphics! Very early placeholders for now Wink


The player has just entered the map, and can only see within a certain radius.


The player has moved around, and the visited areas are clear to see.

There are intended to be two movement styles in the game - keyboard and mouse. Tapping W,S,A,D moves laterally, whereas clicking can move automatically to a specified tile. The pathfinding was never actually intended for enemy movement, since the enemies will not 'move', per se, but will only implement basic 'back and forth' motion to give the illusion of wandering (either walking back and forth on the X or Y axes).

The intention was to allow the player to click on a tile and have them move automatically to that space - thus needing some kind of pathfinding. It probably doesn't look worth doing in the above screenshots, but it was more for the zoomed out view - like you might see in Desktop Dungeons. The fact that you can't 'click' on a destination tile within the fog area means that scenarios involving pathfinding in 'unknown space' are never going to happen.

In answer to your other question re: the dynamic state of the map - the worst case scenario was to have maybe some locked doors, or impassable tiles that can only be traversed with certain equipped items (slime pit / protective boots etc.). They should be minimal interruptions, at best.

I hope this clears up my intentions!
29  Game Development / Newbie & Debugging Questions / Re: Precomputed tile paths for pathfinding? on: 2012-03-06 23:35:23
That's brilliantly explained, thank you. I like the idea of compressing a unified space (like a hallway) into a single point of traversal. As you point out, the cost is simply the 'length' of the hallway.

I could (theoretically) improve upon this a little by implementing the 'forbidden' routes, perhaps as a precalculated step - using the methodology that any concave space is technically impassable (such as a deadend hallway) - and treated as a zone. If the target end point doesn't include this zone, it is effectively dropped from the search graph, since it doesn't contribute in any way to any paths. That way, you'd save N*N additional node checks (where N*N is the area in tiles of the zone in question).

Would this be a useful addition? Or am I barking up the wrong tree?
30  Game Development / Newbie & Debugging Questions / Re: Precomputed tile paths for pathfinding? on: 2012-03-06 23:17:00
At most three? Does this mean that you have no spaces where you will have a square of eight floor tiles? If you think it's more likely that most of your tiles have have two neighbors, instead of three or four, you can use this to greatly simplify your pathfinding.

Sorry, perhaps I didn't explain it well enough. What I meant was that when expanding a search node, I'd only expand in the available walk directions (up, down, left, right), negating the direction from which I've just calculated the values for. From what I understood, when you examine the next node towards the goal, you'd normal expand in all directions - including diagonals - minus those nodes on your closed list. I was under the impression restricting it based on non-diagonal movements only would speed up the pathfinder testing a little?

Wow, I still can't word this properly!
Pages: [1] 2
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (125 views)
2013-05-17 21:29:12

alaslipknot (133 views)
2013-05-16 21:24:48

gouessej (163 views)
2013-05-16 00:53:38

gouessej (155 views)
2013-05-16 00:17:58

theagentd (168 views)
2013-05-15 15:01:13

theagentd (153 views)
2013-05-15 15:00:54

StreetDoggy (197 views)
2013-05-14 15:56:26

kutucuk (221 views)
2013-05-12 17:10:36

kutucuk (220 views)
2013-05-12 15:36:09

UnluckyDevil (224 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.336 seconds with 20 queries.