Results 1 to 10 of 10

Thread: shoot Game Question

  1. #1

    shoot Game Question

    Hi..
    I'm trying to make a FPS game but I have a problem :
    I made a map with many houses and then put player1 (computer player) behind one of these houses and my player (player2) in a opposite side of that house .
    the player1 directly shoot on my player .
    how can I make the Computer player don't shoot at my player unless he see him with out any barrier

    I tried this way :
    I Put GLcube and made it touch my player ,then I made a collision Check if the GLcube collision with map that mean the computer player can't see my player (because GLcube collision with the house )
    unless he can see me.
    but I don't know why the "DistanceTo" procedure gives wrong value to the CubeDepth.
    so I found the Cubedepth not reach to my player and stop it continues about "215" more than it has to be

    the code I used :
    // GLCube1 in the Player1 //
    Player1.PointTo(Player2, YHmgVector);
    GLCube1.CubeDepth := Player1.DistanceTo(Player2);
    GLCube1.Position.Z := GLCube1.CubeDepth/2;

    please if there any another idea or why the code not work tell me about it.
    note : I tried that code before and it's work very well but I don't know now why it doesn't work
    thanks a lot

  2. #2

    Re: shoot Game Question

    you have to seek fo line of sight algorithm , they are many in flash community..just google it

  3. #3

    Re: shoot Game Question

    Interesting algorithm,

    Do i understand what your are trying to do?

    - You have 2 players position, (i guess the direction from position1 to position2 is not necesary axis aligned.

    - you want to check if there is map geometry between position1 and position2,
    - you define a cube from position1 to position2 and then you do a cube collision test against the map, if true then there is somthing between players.

    Sounds good, but i see severals fault there,

    * is this cube rectangular?, i mean the cubedepth seems is the distance between playes, but is that just for the cube z axis?, or cube width and cube height is the same as cubedepth?, if so then cube collision will return true if there is somthing around the player, like behind or to his sides, however player1 is visible to player 2.

    * if the cube is width 1 and height 1 but only cubedepth is toplayer2 distance, then this only work if the cube is an object oriented box (OOB), but this line code you put: "GLCube1.Position.Z := GLCube1.CubeDepth/2;" tould me GLcube seem is a Axis aligned bounding box, (AABB) and this will only work when distance to player2 is only in the Z axis.

    I am not a GLscene users, so i cant tell you exactly what GL primitive to use, but if you want to check if player1 is visible to player2 then i sugest look if there is available a sphere primitive or a raytrace or intersect utility.

    *Using a sphere primitive:
    - You calc a vector from position1 to position2, then normalize the vector (vector length is equal to 1)
    - you do a loop and calc a new position from pos1 toward pos2 using your normalized vector, and scaled to step increment your think best, 5 units step, or 10 units step, whatever.
    - Put a sphere using as center your new position and as radio what ever you thing is best, then do a sphere to map collision, if true then break the loop and return true, there is somthing between player1 and player2.
    - If the loop end and you did not found any collision then there is nothing between players, (or exactly nothing that collide with your desired sized sphere)

    A intersect utility is exactly what i descibed above but finer and using a ray segment.

    You have to optimize your algorithms, checking a line of sight every frame could kill your permormance.





    good luck.



  4. #4

    Re: shoot Game Question

    Maybe something like

    [pascal]
    / GLCube1 in the Player1 //
    Player1.PointTo(Player2, YHmgVector);
    GLCube1.CubeDepth := Player1.DistanceTo(Player2);

    // You can use arccos or maybe there is built in function in GLScene
    // to find out angle between players
    angle := Player1.AngleTo(Player2);
    // angle := DegToRad(angle); // if needed, just make sure it's radians

    GLCube1.Position.X := Player1.Position.X+ GLCube1.CubeDepth * cos(angle);
    GLCube1.Position.Z := Player1.Position.Z+ GLCube1.CubeDepth * sin(angle);[/pascal]

    But actually this should make something good if i understand the idea in GLScene:
    Maybe something like

    [pascal]GLCube1.Position.X := Player1.Position.X;
    GLCube1.Position.Z := Player1.Position.Z;
    GLCube1.PointTo(Player2, YHmgVector);
    GLCube1.CubeDepth := GLCube1.DistanceTo(Player2);[/pascal]

  5. #5

    Re: shoot Game Question

    tpascal : thank you, about your idea
    you told me to put my actor in the sphere and check the collision between the map and the sphere if there is any collision that mean there is a block, but the problem that I found if my player walk to the left and then collision with the wall in this case the computer will not see him but the problem if the computer player was standing on the right of my player in this case he must see my player but because the collision (true)he will not see him .


    User137 : thank you, but my problem not with the code because it's work very well but I don't know why just in this example I get the value from the "DistanceTo" procedure wrong.
    in another example the procedure give me a right distance value between both players but this time it's give me the value + about 215 I don't know why.
    like for example it must give me 600 , so I'll put the depth of the cube 600 in this case the Cube will start from player1 and end in player2 , but it's give me 815 for that it start from player1 and end after player2 .
    so I want to know is there any code or library make the procedure gives a wrong value?
    (the value from "DistanceTo" it must be 600 but it's give me 800)??

  6. #6

    Re: shoot Game Question

    you told me to put my actor in the sphere and check the collision between the map and the sphere if there is any collision that mean there is a block
    no,no, what i said is you have to move that sphere from player1 position to player2 using a linear path and in steps unit you think best, and for each step check sphere collision.

    Actually It is like shooting an imaginary bullet from pos1 to pos2 checking the whole path in the same frame. Maybe you think that is much work, but it is called ray intersect and it is a very commun procedure in video games, please check this:

    http://en.wikipedia.org/wiki/Line_of_sight_%28gaming%29


    ike for example it must give me 600 , so I'll put the depth of the cube 600 in this case the Cube will start from player1 and end in player2 , but it's give me 815 for that it start from player1 and end after player2 .
    If player1 position and player2 position are z axis aligned (like (10,20,200)-(10,20,50) same xy but different Z), then distance is just the z difference between positions, but is they are not axis aligned, (for example a diagonal line from pos1 to pos2 then the distance result is not calculated just using z difference.


  7. #7

    Re: shoot Game Question

    ooooooh now I understand it , it's a good idea I'll try it , but could you see my example and tell me where the problem is because I'm really get angry from it

    Download link
    http://www.zshare.net/download/6879221789f550c8/



    thank you sooooo much

  8. #8

    Re: shoot Game Question

    well there is a good and simple idea or algorithm if you want, you have to link a dummy cube or rectangle with the length u wannt it (like depth 5 meters for example), and it always moves with the actor and another one with the enemies ..
    - then if the dummy boxes intersect or there is collision between them, that's mean that the ennemy has saw you so he can start shooting you..

  9. #9

    Re: shoot Game Question

    thank you for the idea pixin


    please is there anyone can download this example and tell me why the "DistanceTo" procedure gives me wrong value
    http://www.zshare.net/download/6879221789f550c8/

    pleeeeeeeeeeeeeeeeease

  10. #10

    Re: shoot Game Question

    Finally I found the solution

    Thank you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •