Where the heck do you put collision detection
I''m not sure what the best solution is. Should i create a list of all the objects that need to checked for collision and then check them and do whatever when a collision is found, or should i let each object handle its collision when it updates?
any opinions?
Ian Halliday yoPWEENED
A good answer would be: how to fuck I know?!!
nm
I test collisions right after I move an object.
nm
I test collisions right after I move an object.
quote:
A good answer would be: how to fuck I know?!!
Really, I''d have to disagree that that''s a good answer. Namely because it makes no sense.
-----------------
The Goblin
-----------------
"Oh, God..."
"Yes?" <- My Response
- The Goblin (madgob@aol.com)
here is what i do.......
almost all my stuff goes into classes.
for example a character walking on a tile map.....
have a class for the character, a class for the map, a class for NPC''s, etc.....
in each of those classes I will have an update function. I will call everythings update function one time in the main loop. Now each update function will do everything that needs to be done to that object for one frame. Included in this function is checking for collisions to the other objects.
The player will check for collisions with NPC''s and the map
The NPC''s will check for collisions with the player, each other and the MAP
The map doesnt need to check for any collisions so I dont do any collision detection in its update function.
"Yo yo ma"
-Kramer
almost all my stuff goes into classes.
for example a character walking on a tile map.....
have a class for the character, a class for the map, a class for NPC''s, etc.....
in each of those classes I will have an update function. I will call everythings update function one time in the main loop. Now each update function will do everything that needs to be done to that object for one frame. Included in this function is checking for collisions to the other objects.
The player will check for collisions with NPC''s and the map
The NPC''s will check for collisions with the player, each other and the MAP
The map doesnt need to check for any collisions so I dont do any collision detection in its update function.
"Yo yo ma"
-Kramer
"Yo yo ma" -Kramer
quote:
Original post by Goblin
>A good answer would be: how to fuck I know?!!
Really, I''d have to disagree that that''s a good answer. Namely because it makes no sense.
So you didn''t see the connection between the topic?
i let each object handle it itself
what i did was define my geometric primitive, and the general code to intersect any 2 of them (lots of functions!)
basically then for my geometric primitive base class, i defined the virtual functions to intersect said geometric primitive w/ all of the others, including itself, and a general delegating function called FindIntersection( ObjectToIntersect ), which calls the appropriate virtual function to intersect itself w/ the object.
each derived class simply overrides the virtual functions, and the base will call ''em:
there''s also a small rtti type implemetation in that each object has a record of what type of object it is:
enum PrimitiveType{ LineType,Plane,SphereType };
goes somthin like this:
// forward declarations:
class Line;
class Plane;
class Sphere;
class PrimitiveBase:
{
public:
PrimitiveBase( PrimitiveType ): m_PrimitiveType( PrimitiveType ){}
virtual FindIntersection( PrimitiveBase* ObjToInt ) = 0;
protected:
virtual FindIntersectionLine( Line* LineToInt ) = 0;
virtual FindIntersectionPlane( Plane* PlaneToInt ) = 0;
virtual FindIntersectionSphere( Sphere* SphereToInt ) = 0;
PrimitiveType m_PrimitiveType;
}
class Line
{
public:
Line( ): PrimitiveType( LineType ){}
virtual FindIntersection( PrimitiveBase* ObjToInt );
protected:
virtual FindIntersectionLine( Line* LineToInt );
virtual FindIntersectionPlane( Plane* PlaneToInt );
virtual FindIntersectionSphere( Sphere* SphereToInt );
}
Line::FindIntersection( PrimitiveBase* ObjToInt )
{
ObjToInt->FindIntersectionLine( this );
}
Line::FindIntersectionLine( Line* LineToInt )
{
::FindIntersectionLineLine( this,LineToInt );
}
Line::FindIntersectionPlane( Plane* PlaneToInt )
{
::FindIntersectionLinePlane( this,PlaneToInt );
}
etc..
then, just call Object1->FindIntersection( Object2 );
neat, i think.
well, to answer where i do it:
mainloop()
{
GetPlayerInput();
GetNetworkInput();
ProcessAI();
HandleCollisions(); (here)
Render();
}
although handlecollisions is really a part of process AI;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~
-(Drop me a line here n''at)-
what i did was define my geometric primitive, and the general code to intersect any 2 of them (lots of functions!)
basically then for my geometric primitive base class, i defined the virtual functions to intersect said geometric primitive w/ all of the others, including itself, and a general delegating function called FindIntersection( ObjectToIntersect ), which calls the appropriate virtual function to intersect itself w/ the object.
each derived class simply overrides the virtual functions, and the base will call ''em:
there''s also a small rtti type implemetation in that each object has a record of what type of object it is:
enum PrimitiveType{ LineType,Plane,SphereType };
goes somthin like this:
// forward declarations:
class Line;
class Plane;
class Sphere;
class PrimitiveBase:
{
public:
PrimitiveBase( PrimitiveType ): m_PrimitiveType( PrimitiveType ){}
virtual FindIntersection( PrimitiveBase* ObjToInt ) = 0;
protected:
virtual FindIntersectionLine( Line* LineToInt ) = 0;
virtual FindIntersectionPlane( Plane* PlaneToInt ) = 0;
virtual FindIntersectionSphere( Sphere* SphereToInt ) = 0;
PrimitiveType m_PrimitiveType;
}
class Line
{
public:
Line( ): PrimitiveType( LineType ){}
virtual FindIntersection( PrimitiveBase* ObjToInt );
protected:
virtual FindIntersectionLine( Line* LineToInt );
virtual FindIntersectionPlane( Plane* PlaneToInt );
virtual FindIntersectionSphere( Sphere* SphereToInt );
}
Line::FindIntersection( PrimitiveBase* ObjToInt )
{
ObjToInt->FindIntersectionLine( this );
}
Line::FindIntersectionLine( Line* LineToInt )
{
::FindIntersectionLineLine( this,LineToInt );
}
Line::FindIntersectionPlane( Plane* PlaneToInt )
{
::FindIntersectionLinePlane( this,PlaneToInt );
}
etc..
then, just call Object1->FindIntersection( Object2 );
neat, i think.
well, to answer where i do it:
mainloop()
{
GetPlayerInput();
GetNetworkInput();
ProcessAI();
HandleCollisions(); (here)
Render();
}
although handlecollisions is really a part of process AI;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I have no name that you may call me. I am merely Succinct.
~Succinct Demos Online~
-(Drop me a line here n''at)-
-- Succinct(Don't listen to me)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement