I've made a 3d game simulation with animation and all the controls. But whenever i jump, the player remains up in the air without coming back down. Also the player can simply walk through walls. I'm using " colonel - z " for the player and "universe.dbo" for the environment. Can anybody help me plz ?

Thanks

Recommended Answers

All 5 Replies

I would attend to the 'walking through walls' issue first, as the solution to the gravity issue will depend on being able to detect the floor. How are you doing collision detection in general? You might want to go over a few tutorials on the subject such as this one and this one, if you haven't already. It isn't a minor topic - entire books have been written on the subject - but for most purposes, BSP trees are still probably the easiest efficient solution; the chapter on it in Michael Abrash's Graphics Programming Black Book remains an excellent primer on it even after fiteen years.

>>, BSP trees are still probably the easiest efficient solution;

Actually, for simple application, BSP isn't even necessary, simple collision check can suffice

By the way, I'm using dark gdk which has some simple collision detection tools by itself. though when i use the code to detect collision for objects, the program just skips over it without doing any thing. it doesn't even any errors.

>>By the way, I'm using dark gdk which has some simple collision detection tools by itself. though when i use the code to detect collision for objects, the program just skips over it without doing any thing. it doesn't even any errors.

I suggest you review the documentation on dark gdk because either you are not using the collision checker correctly, or it is not a working feature of the library.

i thought you might want to read the code:

#include "DarkGDK.h"
#include "Inventor.h"

void DarkGDK ( void )
{
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbMaximizeWindow ();
	float fCameraAngleX = 0.0;
	float fCameraAngleY = 0.0;
	int ground;
    SetCurrentDirectory ( "media" );
    dbLoadObject ( "universe.dbo", 2 );
    dbSetObjectLight ( 2, 0 );
	dbLoadObject ( "skybox2.x", 3 );
        dbSetObjectLight ( 3, 0 );
        dbSetObjectTexture ( 3, 3, 2 );
        dbScaleObject ( 3, 5000, 5000, 5000 );
	dbLoadObject ( "Colonel-X.X", 1 );
	dbSetObjectSpeed ( 1, 100 );
	dbMoveObject ( 1, -130 );
	dbMoveObjectRight ( 1, 200 );
	dbSetObjectCollisionOn ( 1 );
	dbSetObjectCollisionOn ( 2 );
	dbSetGlobalCollisionOn ();
	while ( LoopGDK ( ) )
	{
		if ( dbUpKey() && dbShiftKey () ){
			dbLoopObject ( 1, 300, 318 );
			dbMoveObject ( 1, -5.0 );
		}else if ( dbUpKey () ){
			dbLoopObject ( 1, 235, 259 );
			dbMoveObject ( 1, -3.5 );
		}else if ( dbDownKey () ){
			dbLoopObject ( 1, 259, 235 );
			dbMoveObject ( 1, 3.5 );
		}else if ( dbRightKey () ){
			dbLoopObject ( 1, 280, 299 );
			dbMoveObjectLeft ( 1, 3.5 );
		}else if ( dbLeftKey () ){
			dbLoopObject ( 1, 260, 279 );
			dbMoveObjectRight ( 1, 3.5 );
		}else if ( dbSpaceKey () ){
			dbLoopObject ( 1, 190, 209 );
			dbMoveObjectUp ( 1, 3.5 );
			dbMoveObject ( 1, -3.5 );
		}else{
			dbLoopObject ( 1, 210, 234 );
		}
		while ( (ground = dbObjectCollision ( 1, 2 )) != 1 )
		{
			dbMoveObjectDown ( 1, 3.5 );
		}
        fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
        fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
        dbXRotateCamera ( fCameraAngleX );
        dbYRotateCamera ( fCameraAngleY );
		//dbRotateObject ( 1, 0, fCameraAngleY, 0 );
		dbPositionMouse ( dbScreenWidth () / 2, dbScreenHeight () / 2 );
		dbHideMouse ();
		dbPositionCamera ( dbObjectPositionX ( 1 ), dbObjectPositionY ( 1 ) + 50, dbObjectPositionZ ( 1 ) + 50 );
		dbSync ( );
	}
	return;
}

i'm not an expert programmer so if you see any mistakes please tell me.
and i checked the documentation but no good results :-(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.