• Advertisement

Archived

This topic is now archived and is closed to further replies.

Where the heck do you put collision detection

This topic is 6246 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
A good answer would be: how to fuck I know?!!

nm

I test collisions right after I move an object.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
quote:
Original post by Goblin

[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.



So you didn''t see the connection between the topic?

Share this post


Link to post
Share on other sites
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)-

Share this post


Link to post
Share on other sites

  • Advertisement