A Shooting tower!
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
A Shooting tower!
Right, so now I am at the point in my game where I need to workout how to make things happen.
The screenshot below describes the situation :
Those sydneys are marching towards that tower, and I need to make that tower start shooting at sydney when she comes close.
The distance thing I guess is simple enough - make the tower constantly poll the enemies distance, and if its within a certain distance, start shooting.
Thing is - dont know if thats the best way to do it.
Also, does anybody have a shooting animation / model, like a bullet, or explosion, or a rocket or something which the tower can propel at the enemies? Whats the best way to do something like this?
Thanks - Andy
The screenshot below describes the situation :
Those sydneys are marching towards that tower, and I need to make that tower start shooting at sydney when she comes close.
The distance thing I guess is simple enough - make the tower constantly poll the enemies distance, and if its within a certain distance, start shooting.
Thing is - dont know if thats the best way to do it.
Also, does anybody have a shooting animation / model, like a bullet, or explosion, or a rocket or something which the tower can propel at the enemies? Whats the best way to do something like this?
Thanks - Andy
Game development blog: http://www.valleyattack.upsetpc.com/
Hi,
If your thinking lasers, your probable best going with some nice special effects using some slim triangles on there to emulate shots. Clever usage of shaders can give some nice effect!
Regarding the distance, the best way to do that is to first get the units on some kind of tiled grid data structure so that when they move they dynamicly change tiles on that grid. This spares computation power. The grid data structure can be used for all kinds of things. Its a form of culling for game objects.
Then in each AI tick the tower can poll all units inside the grid squares on its range for a crude but fast distance function. You can then do the official distance function for extra precision.
This way you save cycles there.
If your thinking lasers, your probable best going with some nice special effects using some slim triangles on there to emulate shots. Clever usage of shaders can give some nice effect!
Regarding the distance, the best way to do that is to first get the units on some kind of tiled grid data structure so that when they move they dynamicly change tiles on that grid. This spares computation power. The grid data structure can be used for all kinds of things. Its a form of culling for game objects.
Then in each AI tick the tower can poll all units inside the grid squares on its range for a crude but fast distance function. You can then do the official distance function for extra precision.
This way you save cycles there.
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
great idea.
Are there any examples of a laser style shooting - sounds exactly what I want, just no idea where to begin.
As for the data grid data structure - how would i begin doing that?
Thanks for your support rui!
Are there any examples of a laser style shooting - sounds exactly what I want, just no idea where to begin.
As for the data grid data structure - how would i begin doing that?
Thanks for your support rui!
Game development blog: http://www.valleyattack.upsetpc.com/
You definetly need to decide what style of weapon you want the tower to have. Should it be a projectile like a bullet, rocket etc or should it be more like a laser beam? What genre game are you doing? Is it a sci-fi game, if so then a laser idea is great, if not then you probably don't want a laser
For the sake of getting something working you could use the portal jpgs in the Irrlicht media folder and stick em in a texture animator and apply them to a billboard which can then be fired at the sydney models using, maybe, a fly straight animator.
As for a laser effect i guess you'd need something like axis aligned billboards and create a quad which stretchs from the tower to the target being shot at, apply a nice 'laser' texture to it and rotate it so that it faces the camera but is also aligned along the line from the tower to the target.
For the sake of getting something working you could use the portal jpgs in the Irrlicht media folder and stick em in a texture animator and apply them to a billboard which can then be fired at the sydney models using, maybe, a fly straight animator.
As for a laser effect i guess you'd need something like axis aligned billboards and create a quad which stretchs from the tower to the target being shot at, apply a nice 'laser' texture to it and rotate it so that it faces the camera but is also aligned along the line from the tower to the target.
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
sounds like the first idea is better - its not going to be too sci fi, but can have some lasers etc in it.
As for the fly straight animator, that wont track the position of the enemy, so really it would need to shoot in front of the person to hit it?
How would I setup the grid terrain layout which has been spoken about?
As for the fly straight animator, that wont track the position of the enemy, so really it would need to shoot in front of the person to hit it?
How would I setup the grid terrain layout which has been spoken about?
Game development blog: http://www.valleyattack.upsetpc.com/
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
ok but i still need walked through creating the particle and making it on the billboard then moving it.
Game development blog: http://www.valleyattack.upsetpc.com/
it would look like the code shown below...
Hope you're having fun there?
Code: Select all
//
// ball of fire projectile, flies straight path, no curve.
//
void BadMojo::shootItBangItsDeadCharlie() {
scene::ISceneNodeAnimator* anim;
scene::ISceneNode* bill;
bool bImALazyBum = true;
bool bImSoLazyICantWriteThisCode = true;
if ( bImALazyBum || bImSoLazyICantWriteThisCode) {
// add light 1 (nearly red)
scene::ILightSceneNode* light1 =
smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(0.5f, 1.0f, 0.5f, 0.0f), 800.0f);
// add fly animator to light 1
anim = smgr->createFlyStraightAnimator(bla,bla,bla);
light1->addAnimator(anim);
anim->drop();
// attach billboard to the light
bill = smgr->addBillboardSceneNode(light1, core::dimension2d<f32>(60, 60));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
bill->setMaterialTexture(0, driver->getTexture("../../media/particlered.bmp"));
// add particle system
scene::IParticleSystemSceneNode* ps =
smgr->addParticleSystemSceneNode(false, light1);
ps->setParticleSize(core::dimension2d<f32>(30.0f, 40.0f));
// create and set emitter
scene::IParticleEmitter* em = ps->createBoxEmitter(
core::aabbox3d<f32>(-3,0,-3,3,1,3),
core::vector3df(0.0f,0.03f,0.0f),
80,100,
video::SColor(0,255,255,255), video::SColor(0,255,255,255),
400,1100);
ps->setEmitter(em);
em->drop();
// create and set affector
scene::IParticleAffector* paf = ps->createFadeOutParticleAffector();
ps->addAffector(paf);
paf->drop();
// adjust some material settings
ps->setMaterialFlag(video::EMF_LIGHTING, false);
ps->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
ps->setMaterialTexture(0, driver->getTexture("../../media/fireball.bmp"));
ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
}
}
Last edited by dlangdev on Wed Jul 02, 2008 12:15 am, edited 3 times in total.
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
oh wow! finally!
Thats quite nice! I like it!
So now that I have something which resembles firing. How can i do the whole tile idea....I found this thread when searching for tile based terrain, and was wondering if I could use my terrain - with this piece of code to somehow generated the 2d tile array for me?
http://irrlicht.sourceforge.net/phpBB2/ ... ed+terrain
Cheers,
Andy
Thats quite nice! I like it!
So now that I have something which resembles firing. How can i do the whole tile idea....I found this thread when searching for tile based terrain, and was wondering if I could use my terrain - with this piece of code to somehow generated the 2d tile array for me?
http://irrlicht.sourceforge.net/phpBB2/ ... ed+terrain
Cheers,
Andy
Game development blog: http://www.valleyattack.upsetpc.com/
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
LMAO!!!!!
That has to be the best reply ive read on a forum!
Love it - it was not a demand but a request!
Andy
That has to be the best reply ive read on a forum!
Love it - it was not a demand but a request!
Andy
Game development blog: http://www.valleyattack.upsetpc.com/
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
The tiling can (and probably should) be independent of the terrain.
Notionally, you're just building an A * B grid (i.e. a 2D array) of tile objects, each of which has a fixed size. A tile object can simply be a collection (array, list) of references to game objects.
If the tiles are fixed size, then finding out which tile an object is on is trival; just divide its X and Z (or Y, whatever your "ground" co-ordinates use) by the tile sizes to find the A and B indices of the tile (remembering to validate them in case the object moves outside the area covered by the tiles).
Have each object store its current tile, or just calculate it before each move (since it's effectively free to do so). Then move it, and calculate which tile it is on now. If it's changed, then remove its reference from the tile that its leaving and add it to the one that its moving to.
When objects want to check for nearby targets (and bear in mind that they don't have to do that every frame; they can do it at a lower frequency, e.g. every 100 or 250ms) then they need to work out the area of tiles which could contain objects of interest, i.e. an area of size (1 + (radius of interest / tile size)) to each side of their current tile.
Then iterate through all those tiles with a couple of for() loops, and iterate through each object in the collections of those tiles, and do your funky thang with each of those objects.
I hope that's clear enough. It's a good coding exercise if you break it down and take it one step at a time, but we can provide psuedocode or sample code if you get stuck.
Notionally, you're just building an A * B grid (i.e. a 2D array) of tile objects, each of which has a fixed size. A tile object can simply be a collection (array, list) of references to game objects.
If the tiles are fixed size, then finding out which tile an object is on is trival; just divide its X and Z (or Y, whatever your "ground" co-ordinates use) by the tile sizes to find the A and B indices of the tile (remembering to validate them in case the object moves outside the area covered by the tiles).
Have each object store its current tile, or just calculate it before each move (since it's effectively free to do so). Then move it, and calculate which tile it is on now. If it's changed, then remove its reference from the tile that its leaving and add it to the one that its moving to.
When objects want to check for nearby targets (and bear in mind that they don't have to do that every frame; they can do it at a lower frequency, e.g. every 100 or 250ms) then they need to work out the area of tiles which could contain objects of interest, i.e. an area of size (1 + (radius of interest / tile size)) to each side of their current tile.
Then iterate through all those tiles with a couple of for() loops, and iterate through each object in the collections of those tiles, and do your funky thang with each of those objects.
I hope that's clear enough. It's a good coding exercise if you break it down and take it one step at a time, but we can provide psuedocode or sample code if you get stuck.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 122
- Joined: Sun May 25, 2008 11:14 pm
- Location: Scotland
- Contact:
Ok brilliant, its just hard for me to test i feel, cos i wont know if its entirely correct without outputting the current positions etc.
So would the best idea be
each enemy on each game loop :
call a function which will iterate over all enemies, find and update their tile positions
Then every game loop :
each tower or defencive unit scan for the tiles around it and shoot if something is near.
I say everygame loop, i suppose as you say it could be every 100ms or every 250ms.
**unsure how to make it do it less often but thats a problem which im sure can be easily sorted later**
I can make a start tonight!
So would the best idea be
each enemy on each game loop :
call a function which will iterate over all enemies, find and update their tile positions
Then every game loop :
each tower or defencive unit scan for the tiles around it and shoot if something is near.
I say everygame loop, i suppose as you say it could be every 100ms or every 250ms.
**unsure how to make it do it less often but thats a problem which im sure can be easily sorted later**
I can make a start tonight!
Game development blog: http://www.valleyattack.upsetpc.com/