FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Gun or cannon? Actual projectile or ray based?

4 posters

Go down

Gun or cannon? Actual projectile or ray based? Empty Gun or cannon? Actual projectile or ray based?

Post  DMRadford Fri Sep 04, 2009 3:28 pm

So I'm in the process of figuring out how to shoot a gun or fire some sort of projectile within SiO2 and so far I'm kinda stumped. As a test I'm trying to get a cannon to fire and knock over a brick wall. I've got the wall, got the physics for that. I've tested the tumbling effect with a simple ramp to give the "cannon ball" its speed. But no matter what I try, I can't figure out how to have the physics turned off until I tap the screen (or whatever) at which point I want to activate physics on the cannon ball and give it a punch in the hind side as if being blown out of a cannon.

Further down that road I'll need to parent the cannonball to the cannon so it can rotate, but right now my biggest problem is getting some momentum behind this thing.

If actually having a cannonball seems too physics heavy or too difficult, I don't have an issue with using some sort of either ray based collision detection or even a pre-animated cannonball path, as long as I can get the visual result of some sort of collision.

Any advice or resources would be very much appreciated.

-David

DMRadford

Posts : 4
Join date : 2009-09-01

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  cgen2 Fri Sep 04, 2009 8:30 pm

Why don't you use the SIO2 particle system?

I, too, am trying to code a shooter of sorts - a machine gun. I haven't yet mastered the particle system but it looks encouraging. I expect it could be applied to your cannon ball.

I would be interested to know how to get bullets to be emitted from the gun that moves and rotates in 3D space. Maybe others could enlighten us ...

cgen2

Posts : 38
Join date : 2008-12-14

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  yarri Fri Sep 04, 2009 11:07 pm

Hi, in the game rideNgive I create a weapon cache in the templateLoading() function:

Code:

         // Load weapon cache
         SIO2object *weapon = sio2ResourceGetObject( sio2->_SIO2resource, "object/weapon" );
         weapon->_btRigidBody->setActivationState(WANTS_DEACTIVATION);
         // create an array of weapon objects using sio2Duplicate...


And then set a flag when the screen is tapped and "fire" the weapon in the templateRender() function:

Code:

      // Shoot the object
      if (weaponfire)
      {
         btVector3 linVel;
         // Aim the weapon based on camera direction
         
         weapon->_SIO2transform->loc->x = player->_SIO2transform->loc->x + 1.5f;
         weapon->_SIO2transform->loc->y = player->_SIO2transform->loc->y + 0.5f;
         weapon->_SIO2transform->loc->z = player->_SIO2transform->loc->z + 3.0f;
         weapon->_SIO2transform->rot->x = (float)sio2Randomui( 360 );
         weapon->_SIO2transform->rot->y = (float)sio2Randomui( 360 );
         weapon->_SIO2transform->rot->z = (float)sio2Randomui( 360 );
         sio2Rotate3D(sio2->_SIO2camera->_SIO2transform->dir, 0.0f, ROTZ-180.0f, 5.0f, weapon->_SIO2transform->dir);
         sio2TransformBindMatrix(weapon->_SIO2transform);
         linVel = btVector3(weapon->_SIO2transform->dir->x, weapon->_SIO2transform->dir->y, weapon->_SIO2transform->dir->z);
         linVel.normalize();
         linVel *= 90.0f;
         weapon->_btRigidBody->getWorldTransform().setFromOpenGLMatrix( weapon->_SIO2transform->mat );
         sio2DisableState( & weapon->flags, SIO2_OBJECT_GHOST );  // SIO2 v1.3.5
         weapon->_btRigidBody->setActivationState(ACTIVE_TAG);
         weapon->_btRigidBody->setLinearVelocity(linVel);
         
         weaponfire = FALSE;
      }

I obviously have more code to manage the weapon cache, but these are the basics. Haven't tested on SIO2 v1.4 yet though.
--yarri

yarri

Posts : 81
Join date : 2009-04-10

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  cgen2 Sat Sep 05, 2009 4:12 am

Yarri,
Your Bullet physics approach seems a good choice for something like a cannonball.

The "weapon->_SIO2transform->rot->x = (float)sio2Randomui( 360 );" ( & same for y & z axes ) code would create a ball, yes? Cool.

I think I'm gonna stick with the particle system for my machine gun though.

But thanks for a great idea.

cgen2

Posts : 38
Join date : 2008-12-14

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  DMRadford Tue Sep 08, 2009 8:06 am

Awesome, thanks! I'm so used to doing this stuff in blender, actually having to code it all is near impossible for me to figure out myself. Doing this stuff in blender is so much easier because of their nodal sensor/controller/actuator setup. Some awesome tutorials (if somebody was up to writing them) would be a comprehensive Blender GE to SiO2 translation.

ie shooting a projectile:
Blender:
Add a keyboard sensor for the fire button, "and" controller, "edit object" actuator, set to add object -> (bullet object) -> linV ~20 and GO!!

SiO2:
Cache the bullet object, sense touch input, on touch input, activate bullet object and add initial linear velocity.

Or something like that, but for all the blender sensors and actuators.

I know that would be a tall order, but I can hope right?

-David

DMRadford

Posts : 4
Join date : 2009-09-01

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  sio2interactive Tue Sep 08, 2009 8:18 am

SIO2 != Blender GE
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  DMRadford Tue Sep 08, 2009 8:35 am

Well I understand that, but having its own programming language, would it be safe to say that (within reason) anything possible in the BGE is possible in SIO2?

-David

DMRadford

Posts : 4
Join date : 2009-09-01

Back to top Go down

Gun or cannon? Actual projectile or ray based? Empty Re: Gun or cannon? Actual projectile or ray based?

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum