Normalizing the direction to check if able to move

Posted by spartan2417 on Game Development See other posts from Game Development or by spartan2417
Published on 2012-11-07T10:58:19Z Indexed on 2012/11/07 11:21 UTC
Read the original article Hit count: 249

Filed under:
|
|

i have a a room with 4 walls along the x and z axis respectively. My player who is in first person (therefore the camera) should have collision detection with these walls. I'm relatively new to this so please bare with me. I believe the way to do this is to calculate the direction and distance to the wall from the camera and then normalize the directions. However i can only get this far before i dont know what to do. I think you should work out the angle and direction your facing?

where _dx and _dz is the small buffer in front of the camera.

float CalcDirection(float Cam_x, float Cam_z, float Wall_x, float Wall_z)
{
    //Calculate direction and distance to obstacle.
    float ob_dirx = Cam_x + _dx - Wall_x;
    float ob_dirz = Cam_z + _dz - Wall_z;
    float ob_dist = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz);

    //Normalise directions
    float ob_norm = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz);
    ob_dirx = (ob_dirx)/ob_norm;
    ob_dirz = (ob_dirz)/ob_norm;

can anyone explain in laymen's terms how i work out the angle?

© Game Development or respective owner

Related posts about 3d

Related posts about collision-detection