Zombie Island - Bug on my game - help plz

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.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Zombie Island - Bug on my game - help plz

Post by prchakal »

Hi ppl,

Im building a game but i have a problem on shot ray, can anyone help me?

The link to download alpha version to see the bug is here:

http://www.devgames.com.br/projetos/vis ... bie-island

or

http://www.prsolucoes.com/downloads/zom ... lpha_1.zip

My code of ray creation test:

Code: Select all

//test
if (receptorEvento.IsKeyDown(KEY_CONTROL) || receptorEvento.mouseState.leftButtonDown == true) {

	core::line3d<f32> ray;
	ray.start = jogadores[0]->getNode()->getPosition();
	ray.end = ray.start + (jogadores[0]->getNode()->getRotation().rotationToDirection()-ray.start).normalize() * 1000.0f; 
	driver->draw3DLine(ray.start, ray.end);

	// create fire ball
	vector3df start = ray.start;
	vector3df end = ray.end;

	ISceneNode* node = 0;
	node = smgr->addBillboardSceneNode( BulletParent,dimension2d<f32>(10,10), start);

	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setMaterialTexture(0, driver->getTexture("./dados/modelos/fireball.bmp"));
	node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);

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

	ISceneNodeAnimator* anim = 0;

	// set flight line

	anim = smgr->createFlyStraightAnimator(start, end, time);
	node->addAnimator(anim);
	anim->drop();

	anim = smgr->createDeleteAnimator(time);
	node->addAnimator(anim);
	anim->drop();
}
//-->>
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

sorry maybe its me bein an idiot or bein lazy but wat is the problem, do u get a error message that u need help with or wat is the bug u r talkin about (ie wat happens that u dont want it to)
"Hey Baby Wobbling Wobbling"
-Russell Peters
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

sorry

Post by prchakal »

Oh man, sorry, i forgot say it.

The bug is because the ray is incorret position, i want shot and make the ray go to front of player, but it go to a fixed position how you can see on game when you shot (left mouse click or control key).

Im trying make the shot going to front, but it go to a diferent position, and i dont know what i make incorrect.

I see others examples but all is based on the camera and use 1st camera position, but on my game i have to do all based on player position...
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

i downloaded ur game and i can see the problem now, well i can see the start position of the ray is correct but the direction the ray points to and ends is incorrect, no matter where u go on the map it always wants to point and end in the same direction
"Hey Baby Wobbling Wobbling"
-Russell Peters
Ravi08
Posts: 249
Joined: Thu Jul 17, 2008 12:25 pm

Post by Ravi08 »

sorry but im nt the best at using line3d but i would suggest lookin the line ray.end..., the only way i can explain wat i think u could do is:

wen the ray is started get the position AND rotation of the node, then wen settin the end create it so it goes 1000.0f, nt sure if this will work but worth a try :?
"Hey Baby Wobbling Wobbling"
-Russell Peters
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

The shooting code from the Demo Example in Irrlicht:

Code: Select all

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

	if (!camera || !mapSelector)
		return;

	SParticleImpact imp;
	imp.when = 0;

	// get line of camera

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

	core::triangle3df triangle;

	core::line3d<f32> line(start, end);

	// get intersection point with map
	const scene::ISceneNode* hitNode;
	if (sm->getSceneCollisionManager()->getCollisionPoint(
		line, mapSelector, end, triangle, hitNode))
	{
		// collides with wall
		core::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
	scene::ISceneNode* node = 0;
	node = sm->addBillboardSceneNode(0,
		core::dimension2d<f32>(25,25), start);

	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/fireball.bmp"));
	node->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);
	node->addAnimator(anim);
	anim->drop();

	anim = sm->createDeleteAnimator(time);
	node->addAnimator(anim);
	anim->drop();

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

	// play sound
	#ifdef USE_IRRKLANG
	if (ballSound)
		irrKlang->play2D(ballSound);
	#endif
	#ifdef USE_SDL_MIXER
	if (ballSound)
		playSound(ballSound);
	#endif
}
May wanna have a look at that example.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

but it already have on line:

Code: Select all

ray.end = ray.start + (jogadores[0]->getNode()->getRotation().rotationToDirection()-ray.start).normalize() * 1000.0f; 
Im test other options (each):

Code: Select all

ray.end = (ray.start + jogadores[0]->getNode()->getRotation()) * 1000.0f; 
				ray.end = (ray.start + jogadores[0]->getNode()->getRotation()).normalize() * 1000.0f; 
				ray.end = ray.start + (jogadores[0]->getNode()->getRotation().rotationToDirection()-ray.start) * 1000.0f; 
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

@Lonesome Ducky

Thx, but im already see it, and it is make from the camera... i want start from node...its different..i dont understand how to do it from de node and not from de camera.

From the camera has too much examples...but not frm the node.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

Please help me :(

My ray/line in is wrong position, as you see on game download. :(
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Something like this should work:

Code: Select all

node->updateAbsolutePosition();

vector3df raystart = node->getPosition();

matrix4 m = node->getAbsoluteTransformation();
vector3df rayend(0,0,raydistance);
m.transformVect(rayend);
raystart and rayend are two points of line. raydistance is lenght or ray.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

@arras - Thanks man, your solution is exactly i need, but have only one bug, after im test too amny things to correct your solution i found it:

Code: Select all

jogadores[0]->getNode()->updateAbsolutePosition();

vector3df start= jogadores[0]->getNode()->getPosition();

matrix4 m = jogadores[0]->getNode()->getAbsoluteTransformation();
vector3df end(500,0,0);

m.transformVect(end);

driver->draw3DLine(start, end);

Where:

jogadores[0] => my player class that have a node object in it
start => start position of line
end => end position of line
500 => length of line (distance)

Thanks man...this is perfect :)
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

When I think about it now, there might be problem with my code. If your node is scaled, endpoint will be scaled too. Instead of m.transformVect(rayend); you may want to use this code:

Code: Select all

jogadores[0]->getNode()->updateAbsolutePosition();

vector3df start= jogadores[0]->getNode()->getPosition();

matrix4 m = jogadores[0]->getNode()->getAbsoluteTransformation();
vector3df end(500,0,0);

m.rotateVect(end);
end += start;

driver->draw3DLine(start, end);
Transformation matrix consist of position, rotation and scale. its only first two you need.
Also updating absolute position might or might not be necessary. Try to remove it to see whats happen. If not sure, let it be, it won't hurt.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

Man, this is OK too.

Im now using it modified.

Your code run great, thanks a lot.
prchakal
Posts: 58
Joined: Thu Sep 24, 2009 12:31 am

Post by prchakal »

What are the best method to verify if my line collide with the enemy node?

I will check the line collision or the node shot collison?

How to check it?
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Easiest is via node bounding box:
bool irr::core::aabbox3d< T >::intersectsWithLine()
Its fast but not too precize. It is ofthen sufficient but if not you whould use some kind of triangle selector on tested node then use
bool irr::core::triangle3d< T >::getIntersectionWithLimitedLine().

You should check example 07.Collision.
Post Reply