Best way to handle shooting in fps game?

Go down

Best way to handle shooting in fps game?

Post  oioioi on Tue Mar 24, 2009 3:09 pm

The best way I can think of now is making a collision ray from camera pos to camera 'look' pos, but the function in sio2_sensor.cc only returns where the ray collides not what it collides with, or did I miss something? So far the only think I can think of is placing a cube at collision spot and check if it collides with a monster/NPC etc. Or is there a better way to handle shooting in a fps game( I'll be surprised if there isn't).

Thanks!

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  meteors on Tue Mar 24, 2009 3:16 pm

I think using simple bounding spheres is a very good way of doing collision detection. All you do is test each frame whather the radius of the spheres intersect. And you can use a larer sphere to increase the hit area.

There are plenty of tutorials online.

Hey by the way, I wanted to mention, in regards to your penguin game: have you seen the film "Happy Feet"? There's an absolutely amazing sequence where you slide down a mountain with the penguins.



-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  oioioi on Tue Mar 24, 2009 3:46 pm

meteors wrote:I think using simple bounding spheres is a very good way of doing collision detection. All you do is test each frame whather the radius of the spheres intersect. And you can use a larer sphere to increase the hit area.

There are plenty of tutorials online.

Hey by the way, I wanted to mention, in regards to your penguin game: have you seen the film "Happy Feet"? There's an absolutely amazing sequence where you slide down a mountain with the penguins.



-j
Thanks, I will try that. And thanks for the movie tip, I will check that out

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  meteors on Tue Mar 24, 2009 4:00 pm

It's a great movie. It doesn't get going until about 40 minutes into it. It's a rather strange film, as it looks like a kids' movie, but has adult themes.


-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  oioioi on Wed Mar 25, 2009 3:35 am

I love those kinds of movies, ever seen Madagascar 2? I love that part when the penguin marries the doll Very Happy . Any one got a link to the Wolfenstein 3D source? It was submitted to appstore a few days ago, and the source code have been released, but I can't find it

EDIT: found it: ftp://ftp.idsoftware.com/idstuff/wolf3d/wolf3d_iphone_v1.0_src.zip

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  sw on Wed Mar 25, 2009 4:01 am

try this :
SIO2objec * HitSio2Object ; /// the object ray hit
///............

_SIO2physic->_btSoftRigidDynamicsWorld->rayTest( camPos, rayTo, rayCallback );
if( rayCallback.hasHit() )
{
btRigidBody* hitRigidbody = btRigidBody::upcast( rayCallback.m_collisionObject );
if( hitRigidbody )
{
* HitSio2Object = (SIO2object*) hitRigidbody->getUserPointer();
btVector3 pos = rayCallback.m_hitPointWorld;
}
}
avatar
sw

Posts : 73
Join date : 2008-10-12

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  oioioi on Wed Mar 25, 2009 4:19 am

Thanks sw!
I will try that later, but I have test examen on Friday Sad so I don't time for it right now

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  meteors on Wed Mar 25, 2009 6:18 am

Question: aren't physics very expensive, even basic collision detection?

Wouldn't bounding spheres be much more efficient? I'm honestly just asking.

Best,
-j
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  oioioi on Fri Mar 27, 2009 6:18 am

Got it working now
Code:

   SIO2object *hit;
   
   btVector3 from( sio2->_SIO2camera->_SIO2transform->loc->x,
              sio2->_SIO2camera->_SIO2transform->loc->y,
              sio2->_SIO2camera->_SIO2transform->loc->z);
   
   btVector3 to( sio2->_SIO2camera->_SIO2transform->dir->x,
    sio2->_SIO2camera->_SIO2transform->dir->y,
    sio2->_SIO2camera->_SIO2transform->dir->z);
   
   
   btCollisionWorld::ClosestRayResultCallback ray( from, to );
   sio2->_SIO2physic->_btSoftRigidDynamicsWorld->rayTest( from, to, ray );
   if( ray.hasHit() )
   {
      btRigidBody* hitRigidbody = btRigidBody::upcast( ray.m_collisionObject );
      if( hitRigidbody )
         hit = (SIO2object*) hitRigidbody->getUserPointer();
   }

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

Post  ColorDelta on Fri Mar 27, 2009 9:42 am

Thanks for sharing your code, oioioi and sw cheers

ColorDelta

Posts : 16
Join date : 2009-03-25
Location : London, UK

View user profile

Back to top Go down

Re: Best way to handle shooting in fps game?

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