best way to use (gun's) bullets

mike1
Posts: 14
Joined: Thu May 03, 2012 8:47 am

best way to use (gun's) bullets

Post by mike1 »

Hi everyone,
I've been playing around with bullet for a few weeks now. I must say that it looks pretty damn good - both easy to use, and seems very powerful and high-performing.

Anyway, I'm still in technical demo stage. I'd like to consult on what's the best way to handle bullets (like: gun's bullets, now Bullet Physics Engine :). I can think of two alternatives:
1. Use rayTrace() (or some other equivalent)
This has the advantage of not needing to add an object to the world, and the high speed of a bullet fired into the air won't confuse Bullet engine
However, I'm not sure how (and if possible) to retrieve the relative position of the hit in the object (to know if it was a headshot, for instance)
2. Add a bullet object to the world and listen to collision events
This is the advantage of being able to know where the object was hit, and to be able to move dynamic objects as a result of the hit (like boxes, etc)
However, I'm not sure if Bullet Engine is supposed to handle such quick (and small) objects moving around the world. Is it?

Thanks a lot!
Mike
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: best way to use (gun's) bullets

Post by Typhontaur »

Hi mike!
I currently use RayTest
In this video, after the first 40 seconds, you can see how it is fast.
Here I do not use a real bullet, but if I were to do that, then I just have to calculate
the final position of the impact and then call the function raytest ()
mike1
Posts: 14
Joined: Thu May 03, 2012 8:47 am

Re: best way to use (gun's) bullets

Post by mike1 »

if you're not using a real bullet - how do you calculate the impact position?
are you applying a force to that position to simulate a bullet hitting it?

Thanks!

*EDIT*
btw, is that video showing open source project? can you by any chance send me the sources so I can learn how to do these cool things?
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: best way to use (gun's) bullets

Post by Typhontaur »

I have a starting point and an ending point. then a line.
Objects that are "holed" from this line, I give a impulse and a force(kickback)

The engine is entirely in C + +. follows the concept of the family quake,
but is not quake, or like doom3. but give you a piece of code is not a problem.

I hope can help you! ;)

Code: Select all

BOOL BTPhysics::PhysRayCast (Vec3 start, Vec3 end, float kick)
{
	BOOL hit = false;
	var st = btVector3(start[0], start[1], start[2]), en = btVector3(end[0], end[1], end[2]);
	btCollisionWorld::AllHitsRayResultCallback callback(st, en);
	physicsWorld->rayTest(st, en, callback);

	for (int i = 0; i < callback.m_collisionObjects.size(); i++)
	{
		btCollisionObject *obj = callback.m_collisionObjects[i];

		if (!obj->isStaticOrKinematicObject())
		{
			var y = ((btRigidBody*)obj)->getCenterOfMassPosition() - callback.m_hitPointWorld[i];

			y.normalize(); y *= kick;

			obj->activate(true);

			var rigd = ((RigidBody*)obj);
			var gamebody = static_cast<gamebody *>(rigd->getUserPointer());

			if (static_cast<gamebody *>(rigd->getUserPointer())->type & TYPES_RAGDOLL)
			{
				RagDoll *rag = (RagDoll*)gamebody->model;
				rag->DestroyBodyPart(rigd);
			}
			else
				rigd->applyCentralImpulse(y);
			hit = true;
		}
	}
	return hit;
}
mike1
Posts: 14
Joined: Thu May 03, 2012 8:47 am

Re: best way to use (gun's) bullets

Post by mike1 »

thanks a lot for the code snippet!
now i see that you can extract the hit point from the rayTrace callback.

i'll dig in further, but some basic testing i made look very promising. thanks!
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: best way to use (gun's) bullets

Post by Typhontaur »

;)

Here a demonstration without..... bullets...with...Bullet :mrgreen:
sorry for quality - captured with Olympus camera - Fraps sucks
music "Typh - 2012 Prophecy"