Collision Detection

Started by
19 comments, last by jolyqr 18 years ago

//******************************************************************************************************************
//Desc: choose the collision response direction. If there is a collision forward, move of 0.5 units backward, etc...
//In: buff contains the movement direction: 'f':forward, 'b':back, 'l':left and 'r':right
//Out: nothing
//****************************************************************************************************************
void Switch(char buff)
{
oldPlayerXPosition=player1.GetX();
oldPlayerZPosition=player1.GetZ();
switch(buff)
{
case 'f':
{
player1.SetPosition(oldPlayerXPosition-0.5f,player1.GetY(),player1.GetZ());
}
break;
case 'b':
{
player1.SetPosition(oldPlayerXPosition+0.5f,player1.GetY(),player1.GetZ());
}
break;
case 'l':
{
player1.SetPosition(player1.GetX(),player1.GetY(),oldPlayerZPosition+0.5f);
}
break;
case 'r':
{
player1.SetPosition(player1.GetX(),player1.GetY(),oldPlayerZPosition-0.5f);
}
break;
}
}
Advertisement
i'm sorry for the above line codes, but i've tried to put them inside the "source" mark up, but it does not work...
I don't even know how to put stuff into a source thingy, I just use the

I wanna become a good programmer for my game :-)
i have noticed that the wierd behaviours happen when i press two button of the keyboard at the same time.

for example, if i press the forward button of the keyboard when i'm colliding a and if at the same time i press the right button, the colliding responses becomes crazy!!! The player gets in the colliding zone and stays inner. therefore, instead of moving backward or sliding on the right, it moves on the left, because the right button has caused another collision ...
A simple solution to this problem is to remember the location of movable objects (which includes the player) from the previous frame. If a collision is detected after attempting to move, just revert to the positions from that previous frame. If objects are moving at high speed (viz, a large proportion of their own bounding-box per frame) this can be unsatisfactory, leaving large gaps between 'in contact' objects, but it is OK for simple purposes.

If you want to know all about the 'proper' way to do collision detection – more than you could ever want to know, I suspect – do a search on the Game Programming or Maths and Physics forums.
could someone explain me how do insert a picture on my post ?

i'm going to draw you a picture. it'll be easier to understand.
<img src="http://www.your.image.com/image.jpg" alt="text for those who can't view images" />
[s]--------------------------------------------------------[/s]chromecode.com - software with source code
excuse me, i don't understand. where should i put the name of my picture ?
do i have to replace the "image.jpg" or "your.image.com"... ?

how to indicate that my picture is on my desk top ?
You can get free image hosting here. Then just use the url they give you.

For example, upload an image called hover.bmp, they will give you a link that you can paste here.Image Hosted by ImageShack.us

< a href="http://imageshack.us">< img src="http://img530.imageshack.us/img530/2001/hover1uq.png" border="0" width="128" alt="Image Hosted by ImageShack.us" /></a >
0xa0000000
Free Image Hosting at www.ImageShack.us

This topic is closed to new replies.

Advertisement