Small enemy collision problem[Solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Small enemy collision problem[Solved]

Post by screwgh »

Hi,

I am new here and I searched for the forum but didn`t found any result. three days further without any progress I think it is time to get some help. I have the folowing code:

shoot.cpp

Code: Select all

/*	Created by --------
	Date created: 17-4-2008
	Using irrlicht game engine
*/
//Including the files


//defining the namespaces to acces easier


//Including the dll file


//Defining variables
	struct SParticleImpact
	{
		u32 when;
		core::vector3df pos;
		core::vector3df outVector;
		core::array<SParticleImpact> Impacts;
	};

	//ITriangleSelector* mapSelector;
	core::array<SParticleImpact> Impacts;

//Defining functions

	void shoot()
{
	
    ISceneManager* sm = device->getSceneManager();
	ICameraSceneNode* camera = sm->getActiveCamera();

	ISceneNode* selectedSceneNode = 0;
	ISceneNode* lastSelectedSceneNode = 0;

	selectedSceneNode = sm->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);
    
	
	SParticleImpact imp;
	imp.when = 0;

	vector3df start = camera->getPosition();
	vector3df end = (camera->getTarget() - start);
	end.normalize();
	start += end*8.0f;
	end = start + (end * camera->getFarValue());

	triangle3df triangle;

	line3d<f32> line(start, end);

	// get intersection point with map
	if (sm->getSceneCollisionManager()->getCollisionPoint(line, selector, end, triangle ))
	{
		// collides with wall
		vector3df out = triangle.getNormal();
		out.setLength(0.03f);

		imp.when = 1;
		imp.outVector = out;
		imp.pos = end;
	}
	else
	{
		// doesnt collide with wall
		core::vector3df start = camera->getPosition();
		core::vector3df end = (camera->getTarget() - start);
		end.normalize();
		start += end*8.0f;
		end = start + (end * camera->getFarValue());
	}


	// create fire ball
	fire = sm->addBillboardSceneNode(0,
	core::dimension2d<f32>(25,25), start);

	fire->setMaterialFlag(video::EMF_LIGHTING, false);
	fire->setMaterialTexture(0, device->getVideoDriver()->getTexture("C:/Gaming/irrlicht-1.4/media/fireball.bmp"));
	fire->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);

	f32 length = (f32)(end - start).getLength();
	const f32 speed = 0.6f;
	u32 time = (u32)(length / speed);

	scene::ISceneNodeAnimator* anim = 0;

	// set flight line
	anim = sm->createFlyStraightAnimator(start, end, time);
	fire->addAnimator(anim);
	anim->drop();

	anim = sm->createDeleteAnimator(time);
	fire->addAnimator(anim);
	anim->drop();
	
	if(collisionB(fire, enemy))
	{
		printf("Enemy hit\n");
	}


	if (imp.when)
	{
		// create impact note
		imp.when = device->getTimer()->getTime() + (time - 100);
		Impacts.push_back(imp);
	}
}



//Defining classes
main.cpp

Code: Select all

/*	Created by -----------
	Date created: 8-4-2008
	Using irrlicht game engine
*/
//Including the files
#include "main.h"
#include "collision.h"
#include "shoot.h"
#include "keys.h"
#include <irrlicht.h>

//defining the namespaces to acces easier
using namespace irr;

//Including the dll files


//Defining functions


// Defining variables
ISceneNode* sphere;	//draws cube in scene


//Defining classes

	

int main()
{
	device = createDevice(EDT_DIRECT3D9, //Creating the irrlicht device with direct3D
							dimension2d<s32>(screenW,screenH), //Size of window declared in main.h
							64,		//Bits per pixel in fullscreen mode
							false,	//Fullscreen true or false
							false,	//Stencil buffer shadows
							false,	//Vertical sync
							0);		//User defined receiver
	
	device->setWindowCaption(L"Hero project");								//Setting the title of the window
	MyEventReceiver receiver; //This is the event receiver for moving the camera
	device->setEventReceiver(&receiver); //Set the receiver to the device


	IVideoDriver* driver = device->getVideoDriver();						//Easier to access video driver
	ISceneManager* smgr = device->getSceneManager();						//Easier to access Scenemanager
	IGUIEnvironment* guienv = device->getGUIEnvironment();					//Easuer to access GUI Environment

	//Mapping the correct keys for moving the camera
	SKeyMap keyMap[8];
	//Forward
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;
	//Backward
	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_KEY_S;
	//Strafe left
	keyMap[3].Action = EKA_STRAFE_LEFT;
	keyMap[3].KeyCode = KEY_KEY_A;
	//Strafe right
	keyMap[4].Action = EKA_STRAFE_RIGHT;
	keyMap[4].KeyCode = KEY_KEY_D;
	//Jump
	keyMap[5].Action = EKA_JUMP_UP;
	keyMap[5].KeyCode = KEY_SPACE;


	device->getFileSystem()->addZipFileArchive("C:/Gaming/irrlicht-1.4/media/map-20kdm2.pk3");	//Load quake map 
	IAnimatedMesh* qMap = smgr->getMesh("20kdm2.bsp");//Load mesh from zip file above
	
	for(int x=0; x<KEY_KEY_CODES_COUNT; x++)													//For key handling
			keys[x] = false;									
	
	ISceneNode* scene = 0;																		//Load a scene node

	if(qMap)
		scene = smgr->addOctTreeSceneNode(qMap->getMesh(0));									//Add scene node for rendering

	if (scene)
	{
		scene->setPosition(vector3df(-1300, -144, -1229));										//Translate the level
		selector = smgr->createOctTreeTriangleSelector(qMap->getMesh(0), scene, 128);			//Optimize the scene draw only geometry
		scene->setTriangleSelector(selector);													//Set triangle selector for collission detection
	}


	ICameraSceneNode* camera = camera = smgr->addCameraSceneNodeFPS(0, 250.0f, 400.0f, 0, keyMap, 8, false, 0.5f);//Add a camera to the scene manager on the given position
	camera->setPosition(vector3df(100, 100, 100)); //Change camera position

	//Calculate the radius of the scene node
	const core::aabbox3d<f32>& box = camera->getBoundingBox();//returns the axis of the node
	core::vector3df radius = box.MaxEdge - box.getCenter();//Write the axis to a vector3df


	//Animate a scene node for collision 
	if(selector)
	{
        ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(//Create collision detection
									selector,	//With the triangle selector
									camera,		//Manipulate the camera node so it cannot walk thru walls
									vector3df(radius.X+29,radius.Y+49,radius.Z+5), //Collission detection and response (radius)
									vector3df(0,-2.0f,0),	//Gravity per second xYz
									vector3df(0,30,0));		//Ellipsoid for collision detection
		selector->drop();
		camera->addAnimator(anim); //Animate camera with the scene node
		anim->drop();//Drop the animator
	}
	
	device->getCursorControl()->setVisible(false);//Set the visability for the mouse cursor
	

	// add 3 animated faeries.

        video::SMaterial material;
        material.setTexture(0, driver->getTexture("C:/Gaming/irrlicht-1.4/media/faerie2.bmp"));
        material.Lighting = true;

        scene::IAnimatedMesh* faerie = smgr->getMesh("C:/Gaming/irrlicht-1.4/media/faerie.md2");

        
        enemy = smgr->addAnimatedMeshSceneNode(faerie);
        enemy->setPosition(core::vector3df(100,0,150));
        enemy->setMD2Animation(scene::EMAT_RUN);
        enemy->getMaterial(0) = material;

        material.setTexture(0, 0);
        material.Lighting = false;

        // Add a light

        smgr->addLightSceneNode(0, core::vector3df(100,0,280),
                video::SColorf(1.0f,1.0f,1.0f,1.0f),
                10000.0f);



	//Makes a skybox for nice surrounding
	ISceneNode* SkyBox = smgr->addSkyBoxSceneNode
		(
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_up.jpg"),
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_dn.jpg"),
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_ft.jpg"),
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_bk.jpg"),
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_rt.jpg"),
			driver->getTexture("C:/Gaming/irrlicht-1.4/media/irrlicht2_lf.jpg")
		);


	//Infinity loop to draw everything
	while(device->run())
	{
		if( keys[KEY_KEY_X])
		{
			shoot();
			/*while(fire)
			{
				fire->setPosition(fire->getPosition());
				fire->updateAbsolutePosition();
				printf("pos X:%2.4f\n, pos Y:%2.4f\n, pos Z:%2.4f\n", fire->getAbsolutePosition().X, fire->getAbsolutePosition().Y, fire->getAbsolutePosition().Z);
			}*/
		}

		driver->beginScene(true, true, SColor(255,100,101,140));	//Must draw between begin and end. Begin drawing
		//////////////////////////////////////////////////////////////Begin drawing

		
		
		smgr->drawAll();											//Scenemanager drawing
		
		//Draw crosshair
		driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH-8,cenW+2,cenH-3) ); //above 
		driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW+5,cenH,cenW+10,cenH+2) ); //right 
		driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH+5,cenW+2,cenH+10) ); //down 
		driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW-8,cenH,cenW-3,cenH+2) ); //left 
		driver->draw2DRectangle( SColor(255,255,255,255), rect<s32>(cenW,cenH,cenW+2,cenH+2) ); //center of screen


		guienv->drawAll();											//Gui environment drawing

		
		//////////////////////////////////////////////////////////////End drawing
		driver->endScene();											//Stop drawing
	}

	device->drop();
	 return 0;

}

collision.h

Code: Select all


/*	Created by ---------
	Date created: 17-4-2008
	Using irrlicht game engine
*/
//Including the files


//defining the namespaces to acces easier


//Including the dll file


//Defining variables


//Defining functions

bool collision(ISceneNode* one, ISceneNode* two, int size) { 
	if(one->getPosition().getDistanceFrom(two->getPosition()) < size) 
    return true; 

   return false; 
} 


bool collisionB(ISceneNode* one, ISceneNode* two) { 
	if(one->getTransformedBoundingBox().intersectsWithBox(two->getTransformedBoundingBox())) 
    return true; 

   return false; 
} 

//Defining classes


main.h

Code: Select all

/*	Created by ----------
	Date created: 17-4-2008
	Using irrlicht game engine
*/
//Including the files
#include <irrlicht.h>
#include <stdio.h>
#include <wchar.h>

//defining the namespaces to acces easier
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

//Including the dll file
#pragma comment(lib, "Irrlicht.lib")

//Defining variables
bool keys[irr::KEY_KEY_CODES_COUNT];//For key handling
IrrlichtDevice *device;
ITriangleSelector* selector=0;
IAnimatedMeshSceneNode* enemy = 0;
ISceneNode* fire = 0;

int screenW = 800;
int screenH = 600;
int cenW = screenW / 2;
int cenH = screenH / 2;

//Defining classes
class main : public IEventReceiver
{
public:

	virtual bool OnEvent(const SEvent& event);

private:

};

class MyEventReceiver: public IEventReceiver
{
public:
	virtual bool OnEvent(const SEvent&  event)
	{
		if(event.EventType == irr::EET_KEY_INPUT_EVENT)
		{
			keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
			return false;
		}
		return false;
	}
};


the problem is that the bullet only hit the enemy if I stand next to the enemy the start position of the bullet. But I want to use the position of the bullet to hit the enemy from far away I already tried changing the start and end values of the createflystraight... but that worked a little. I got two bullets and one didn`t collide with the enemy. Does anyone has and idea how I can get this right.

The wall collision is good that works great but the enemy collision doesnt work. maybe some sugestion where I can think about thanks in advanced
Last edited by screwgh on Fri Oct 17, 2008 10:41 pm, edited 1 time in total.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

I didn't try it, but I think your problem is that the bullet moves more than the depth of the target's bounding box each frame.
You're using method 1, which doesn't work:
Image
Method 2: Make a box that is N units larger than the target's box, where N is the size of the projectile, and collide it with the line that the projectile is travelling along (a line from the position at the last frame, to the new position)
Method 3: Create a bounding box as wide and deep as the projectile, and as long as it travels in one frame, transform the target's box into this space and do the collision between boxes.

Or you could just make the projectile go a lot slower! :lol:
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Thanks

Post by screwgh »

Thank you for the fast reply. First I will take a look at the speed hopefully then he wil hit the enemy and from there I will work the box sizes out.

Thank you for the great explaination

New info>

I adjusted the speed the bullet get as slow as needed but no collision. I think he doesnt refresh the position of the bullet. I tried to update the absolute position like it is showed in main.cpp but he get stuck at the beginning point. For some reason he don`t adjust the position. have an idea?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

The position of "fire" only updates in drawAll, so you have to check for a collision after drawAll not in shoot()

Currently you've creating new fireballs every frame, if the user is holding the key down
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Changes

Post by screwgh »

I put the collision detection after the draw all. He makes a hit but when hitting the wall the program gives error "acces ciolation reading location ..." This is because the fireball is deleted and I did this after draw all.

small main.cpp

Code: Select all

if(fire)
{
     if(collision(fire, enemy, 100))
     {
          printf("Enemy hit\n")
     }
}
You are right that the gun is just shooting like hell now. I gonna take a look at that now. Thanks for youre great help I am a little bit further I hope :D. I keep you updated about the rest of the progress. Your site is looking cool with the small games :D

EDIT:

I have some progress, but it is still hanging after it hits the wall. I put some hit booleans but that didn`t work either. I made it so, when hitting one time there is no collision detection anymore than the game doesn`t hang. I going to work on it tomorrow and let know how it goes.
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Some changes

Post by screwgh »

After a lot of code trying I code this:

- Collision detection not in shoot();
- Collision with wall and enemy works now

But I got the following problem:
- The bullet goes through the enemy and wall and after a while the programs stops with the following error:

Unhandelded exception ...... violation reading location: This is occur in the collision

Code: Select all

bool collisionB(ISceneNode* one, ISceneNode* two) 
{ 
	if(one->getTransformedBoundingBox().intersectsWithBox(two->getTransformedBoundingBox()))
	{
		return true; 

	}
   return false; 
} 
Here some code of the main.cpp

Code: Select all

guienv->drawAll();											//Gui environment drawing
	
		
		if(fire && anim)
		{
			printf("debug \n");

			if(hit==false)
			{
				if(collisionB(fire, enemy))
				{
					printf("Enemy Hit\n");
				}
			}
			else
			{
				//hit=false;
			}
		}

		if(fire && qMap)
		{
			if(collisionB(fire, scene))
				{
					printf("Wall Hit\n");
				}
		}


		
		//////////////////////////////////////////////////////////////End drawing
		driver->endScene();											//Stop drawing
I think it is because the bullet is terminated when it is out of sight so the bullet is no more but the collision detection is still working. But he without a bulet.

My question is how can I make it so, that when bullet hits wall or enemy that the is deleted and the collision detection knows it?

Anyone have and idea?
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

Post by robertgarand »

Hi,
I worked a great deal on this class and routine when i started.
It is not very good looking, but it works flawlessly.
If you want your bullet to fly straight just take out the gravity from the equation(I indicate the place with+++). I have my canon direction and position, just calculate trajectory of bullet out of it
Then you do collision detection, and then update every frame. its quick enough for me,and it is easy to modify the precision needed from player, just increase or decrease collide_distance. Like in Hard, normal, easy...
If you have any question, just come back to me.
Regards,
Robert
PS there may be a few }}} missing...did not copy all routine,
I check collision with other "enemies"

Code: Select all


class cshell
	{
	public:
	bool	isVisible;
	static int n_shell;
	irr::f32 speed;
	irr::scene::ISceneNode* pshell;
	irr::core::vector3df angle;
	irr::core::vector3df direction;
	irr::core::vector3df position;
	irr::u32 last_time;
	cshell();
	~cshell();
	};


void tir()
{
	if (!selector || pause)
		return;
	if (nshell == data_level[current_level].max_shellc -1)
	    {// play sound empty barrel
		irrsound->play2D(clink_sound);
		return;
	    }

        timer=Device->getTimer();
        now = timer->getTime();
	// create shell data when use
	nshell++;
	int fill=0;
	while (shell[fill].isVisible){fill++;}
	shell[fill].position=canon->getPosition()+ core::vector3df(1,6,-5);
	shell[fill].isVisible = true;
	shell[fill].pshell->setVisible(true);
	
	shell[fill].last_time = now;
//inverting angles x rotation gives y angle, vice versa
//make it rad
	shell[fill].direction.X = sinf ( core::DEGTORAD * canon->getRotation().Y) * correctiony;
	shell[fill].direction.Y = sinf (-core::DEGTORAD * canon->getRotation().X) * correctionx;
	shell[fill].direction.Z = cosf ((core::DEGTORAD * canon->getRotation().Y)*correctionz) + cosf ((core::DEGTORAD * canon->getRotation().X)*correctionz);
// play sound cannon shooting shell
	if (canon_sound)
	irrsound->play2D(canon_sound);
	points-=10;
}
//updating shell position, and tanks, jets, etc=================================
//checking if they reach ground without impact==================================
void update()
{
	core::triangle3df triangle;
	core::line3d<f32> line;
	core::vector3df movement;
	core::vector3df out;
	core::vector3df end;
	core::vector3df start;
	SParticleImpact imp;
	imp.when = 0;
	timer=Device->getTimer();
	now = timer->getTime();
//	if (shell[0].last_time ==0) {shell[0].last_time = now-10;return;}

	//update les shell
	if (nshell > -1)
	{
		for ( int i =0; i < data_level[current_level].max_shellc; i++)
			{if (shell[i].isVisible)
				{
               	f32 lapse = (now - shell[i].last_time ) * data_level[current_level].shell_speedc;
				shell[i].direction = data_level[current_level].gravityc + shell[i].direction;+++++++++++
				movement = shell[i].direction * lapse;
				shell[i].position += movement;
				shell[i].pshell->setPosition(shell[i].position);
				shell[i].last_time = now;
				}
			}

//checking collision with ground
//if so, changing attributes of shell to stop updating
	for ( int i =0; i < data_level[current_level].max_shellc; i++)
	{if (!shell[i].isVisible) continue;
	start = shell[i].position;
	end = shell[i].position + movement;
	line.setLine(start, end);

	if (smgr->getSceneCollisionManager()->getCollisionPoint(
			line, selector, end, triangle))
		{out = triangle.getNormal();
		out.setLength(0.06f);
//getting data for pos, time of impact
		imp.when = 1;
		imp.outVector = out;
		imp.pos = shell[i].position- movement;
//one shell less
		shell[i].isVisible = false;
          shell[i].position = deadzone;
          nshell--;
          shell[i].pshell->setVisible(false);
		}
//if shell is too far off, reset it
		else if ((shell[i].position.Y < 0)
          ||(shell[i].position.Z> data_level[current_level].length)
          ||(shell[i].position.Z<-300))

		{
          shell[i].isVisible = false;
          shell[i].position = deadzone;
          nshell--;
          shell[i].pshell->setVisible(false);
          imp.when = 1;
          imp.outVector = core::vector3df(0.0f,0.06f,0.0f);
		imp.pos = shell[i].position- movement;
          }

		if (imp.when)
		{
		// create impact note
		imp.when = Device->getTimer()->getTime()+ 100;
		Impacts.push_back(imp);
		imp.when =0;
		}
}

//checks collision between bullet and enemys====================================
//==============================================================================
void check_collision()
{
core::vector3df pos;
core::vector3df out;
SParticleImpact imp;
f64 distance;
irr::f32 distance_x,distance_z;
imp.when = 0;
//checking collision between shells and enemy
if ((jet[0].n_jet < 0)&(tank[0].n_tank<0)) return;//no jet no tank to hit, exit
if (nshell <0) return;//no shells on screen exit
	for ( int i =0; i < data_level[current_level].max_shellc; i++)
	{if (!shell[i].isVisible)continue;//if shell is not visible , next shell
	    for (int j =0; j<data_level[current_level].max_jetc+current_wave; j++)//check with jets
	    {if (jet[j].isDead) continue;//already dead, next jet
			if( f64 distance = shell[i].position.getDistanceFrom(jet[j].position)< collide_distance)
//bullet and jet collide
	   		{jet[j].dying = true;
//one less shell
	   		shell[i].isVisible = false;
	   		shell[i].position=deadzone;
	   		shell[i].pshell->setVisible(false);
	   		nshell--;
	   		out = jet[j].position;
			out.setLength(0.06f);
//getting data for pos, time of impact
			imp.when = 1;
			imp.outVector = core::vector3df(0.0f,0.3f,0.0f);
			imp.pos = jet[j].position;
			imp.node=jet[j].jet_mesh;
			if (imp.when)
				{
// create impact note
				imp.when = Device->getTimer()->getTime()+ 100;
				Enemy_Impacts.push_back(imp);
				}
			}
         }
If it can't be writen, it can't exist
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Hi

Post by screwgh »

Thanks for youre reply I gonna take a look of what I can use.
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

A little bit further

Post by screwgh »

I see there are a lot of problems with colission on the forum. I got a little but further but he still doesn`t do what I want.

The checking of colission is going well I can check te enemy now without
errors but the ISceneNodeAnimator* anim = 0; wont drop.

here is some important code:

main.cpp

Code: Select all

while(device->run())
	{

		if( keys[KEY_KEY_X])
		{
			shoot2();
		}

		driver->beginScene(true, true, SColor(255,100,101,140));	//Must draw between begin and end. Begin drawing
		//////////////////////////////////////////////////////////////Begin drawing

		if(fire)
		{
			fire->grab();
			if(collisionB(fire, enemy))
			{
				printf("Raak\n");
				anim = smgr->createDeleteAnimator(1);
				fire->addAnimator(anim);
				anim->drop();
			}
		}
		
		smgr->drawAll();											//Scenemanager drawing

		if(fire && fire->drop())
			fire=0;
shoot2.h

Code: Select all

shoot2()
{
	ISceneManager* smgr = device->getSceneManager();//Get scenemanager
	ICameraSceneNode* camera = smgr->getActiveCamera();//Get Camera

	vector3df start = camera->getPosition();//Start position of bullet
	vector3df end = camera->getTarget() - start;
	end.normalize();
	start += end*8.0f;
	end = start + (end * camera->getFarValue());
	//vector3df end = selectedSceneNode->getPosition();
		
	//Create fireball
	fire = smgr->addBillboardSceneNode(0, dimension2d<f32>(25,25), start);
	fire->setMaterialFlag(video::EMF_LIGHTING, false);
	fire->setMaterialTexture(0, device->getVideoDriver()->getTexture("C:/Gaming/irrlicht-1.4/media/fireball.bmp"));
	fire->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);

	//properties for flight line
	f32 length = (f32)(end - start).getLength();
	const f32 speed = 0.8f;
	time = (u32)(length / speed);

	// set flight line
	anim = smgr->createFlyStraightAnimator(start, end, time);
	fire->addAnimator(anim);
	anim->drop();
    

}
main.h

Code: Select all

//Defining variables
bool keys[irr::KEY_KEY_CODES_COUNT];//For key handling
IrrlichtDevice *device;
ITriangleSelector* selector=0;
IAnimatedMeshSceneNode* enemy = 0;
ISceneNode* fire = 0;
ISceneNodeAnimator* anim = 0;
bool hit = false;
bool hitw = false;
u32 time;
When I am starting the program it works all well with the colission without any errors but the anim IsceneNode just wont drop(). I looked at my sceneManagers etc.. but as far I can see everything seems okay but it isn`t otherwise it should work. Does anyone has an idea?

Thanks in advance.
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

Shooting at phantom

Post by robertgarand »

Hi,
I tried to use Irrlicht native routine fro enemy shooting. But the flytraightanimator don't take in account the new position of your enemy.
You calculate trajectory at time x, but by the time the bullet reach end of course, the enemy is somewhere else, at (x+lapse)*movement, not at end you used in animator,(except if it is static enemy, as a turret)...
Collision detection must be made on frame to frame basis. After displacement is made. Otherwise you get strange side effect.
Hope I made it clear :|
Regards,
Robert
If it can't be writen, it can't exist
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Thanks

Post by screwgh »

Thank you for the clear explanation.

But I don`t understand I realy, because I just use the flyStraightAnimator for the bullit to fly to his end position. But the colission detection happens every frame that is why it is in the while(device->run()) loop. Correct me if I am wrong.

Beside that at the moment I just have static enemy the enemy is just in one place and dos not move. The problem is not the colission at the moment but just the createDeleteAnimator() he just don`t dissapear for some reason I have been busy for over a lot off hours to get it dissapear but it is just not working.

So if anyone has sugestion or hint about it that would be great. Or is it better to do bullet animation frame by frame like robertgarand says? so that I create a bullet and just move it every frame in the Z direction? till it hit wall or enemy?

Thanks for the comments
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Shooting at phantom

Post by Acki »

robertgarand wrote:I tried to use Irrlicht native routine fro enemy shooting. But the flytraightanimator don't take in account the new position of your enemy.
You calculate trajectory at time x, but by the time the bullet reach end of course, the enemy is somewhere else, at (x+lapse)*movement, not at end you used in animator,(except if it is static enemy, as a turret)...
but isn't this what it's used to be IRL ???
if I have a moving target and I shoot at it then I won't hit it at the point I was targeting on...
I'll have to calculate it's speed and hold before it so the target "runs" into the bullet...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

The FlyStraightAnimator used in the Demo app is a very simple way of doing a very simple projectile. It's meant to serve as a demonstration of how to use an animator, not as a suggestion for how you should implement your own projectiles.

The core issue here is that game development is not very simple, and Irrlicht is not a game engine. If you want to develop any serious applications, you should be prepared to apply some thought to your requirements and design, and not just copy and paste bits and pieces of code from various places, mash them together, and then ask why they're not producing the behaviour that you wanted.

Rant over, I would suggest not using Irrlicht animators for projectiles, and instead do some background reading on collision detection strategies.

The simplest useful strategy is usually a line / box (or line / sphere or line / cylinder) collision, using the start and end points of the projectile during each of its movement steps, and the bounding boxes (and then triangles, if necessary) of each collidable object.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
screwgh
Posts: 19
Joined: Tue Oct 14, 2008 12:27 am

Post by screwgh »

So the bottom line is that I should think more about the aspects of colission and try to figure a own colission detection and a shoot meganism?

a little offtopic
I always thought that good copy pasting of code was a programmers way of living why try to invent something that already excist. After all my excpierence is that with copying code you still have to get into code and background of everything but it gets you motivated to get started. And after all you spend the same ammount of time, it is not lazyness just a motivation isue.

But now I am already motivated to make it work so I while get deeper in the colission detection and shoot meganism. Hopefully something good will rollout.

Thanks for the reply.
night_hawk
Posts: 153
Joined: Mon Mar 03, 2008 8:42 am
Location: Suceava - Romania
Contact:

Post by night_hawk »

Yeah, copy-pasting is good, but doesn't work. Copy-paste-edit! Now that's what works.
Post Reply