User Tag List

Results 1 to 7 of 7

Thread: OpenGL, 3D game and collision with wall

  1. #1
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2007
    Location
    Poland
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OpenGL, 3D game and collision with wall

    Hello.
    I'm trying to make simple 3D game via OpenGL extension. At first I was having a problem with movement, because the options "forwards" and "backwards" in camera allows to fly in game, but I solved it using trigonometry with X and Z of camera. Also I added gravity and collision with top of 3d boxes. It works well.

    But I'm stuck with, I guess simple, problem. How to make an effect such as in other 3D games when I go forward into the wall, while I'm in front of it I'll get stopped while pressing "w", but when I change angle of view, I'll be moving faster on side depending of direction and my camera angle?

  2. #2
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    Hey Grim!

    Its great to hear others are working with OpenGL in MMF2


    There are a number of methods to achieve what your talking about; the following in a somewhat simple implementation

    I assume your movement code looks something like the following

    Camera:
    X position = X position + Sin ( Y Angle )
    Z position = Z position + Cos ( Y Angle )

    Change it to the following

    Camera:

    IF location specified by (X position + Sin ( Y Angle ), Z position) is not inside something solid THEN
    X position = X position + Sin ( Y Angle )
    ENDIF

    IF location specified by (X position, Z position + cos( Y Angle )) is not inside something solid THEN
    Z position = Z position + Cos ( Y Angle )
    ENDIF

    Performing separate collision detections for separate dimensions allows the player to slide along a wall instead of simply being unable to approach it.

    I would love to see your project!

    And if you have further questions please ask

  3. #3
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2007
    Location
    Poland
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    Thank you for the reply.

    Well, you said there must be a negate of collision to allow X or Z moving. At first I had exactly like you said:
    Code:
    *Repeat while "W" is pressed
    - (OpenGL Camera) Set X Position to: X( "OpenGL Camera" )+Sin(Yaw( "OpenGL Camera" ))
    - (OpenGL Camera) Set Z position to: Z( "OpenGL Camera" )+Cos(Yaw( "OpenGL Camera" )+180)
    And it works well when there are no walls. :P

    I was trying to make a dependence of collision with your helpful post, so I made this that way:
    Code:
    *Repeat while "W" is pressed
    *Alterable Value A of ("Valuer") = 0
    - (OpenGL Camera) Set X Position to: X( "OpenGL Camera" )+Sin(Yaw( "OpenGL Camera" ))
    
    *Repeat while "W" is pressed
    *Alterable Value B of ("Valuer") = 0
    - (OpenGL Camera) Set Z position to: Z( "OpenGL Camera" )+Cos(Yaw( "OpenGL Camera" )+180)
    To make a negate collision I used two ifelse object in following events:
    Code:
    *(OpenGL MS3D) On object loop
    *(IfElse1)Start Nested IF 0
    *Y("OpenGL Camera") > Y("OpenGL MS3D") - 20
    *Y("OpenGL Camera") < Y("OpenGL MS3D") + 20
    *X("OpenGL Camera") + Sin(Yaw("OpenGL Camera")) * 2 > X("OpenGL MS3D") - 12
    *X("OpenGL Camera") + Sin(Yaw("OpenGL Camera")) * 2 < X("OpenGL MS3D") + 12
    *Z("OpenGL Camera") > Z("OpenGL MS3D") - 12
    *Z("OpenGL Camera") < Z("OpenGL MS3D") + 12
    *(IfElse1)End Nested IF
    - ("Valuer") Set Alterable Value A to 1
    
    *(IfElse1)Nested Else 0
    - ("Valuer") Set Alterable Value A to 0
    
    *(OpenGL MS3D) On object loop
    *(IfElse2)Start Nested IF 0
    *Y("OpenGL Camera") > Y("OpenGL MS3D") - 20
    *Y("OpenGL Camera") < Y("OpenGL MS3D") + 20
    *X("OpenGL Camera") > X("OpenGL MS3D") - 12
    *X("OpenGL Camera") < X("OpenGL MS3D") + 12
    *Z("OpenGL Camera") + Cos(Yaw("OpenGL Camera")) * 2  > Z("OpenGL MS3D") - 12
    *Z("OpenGL Camera") + Cos(Yaw("OpenGL Camera")) * 2  < Z("OpenGL MS3D") + 12
    *(IfElse2)End Nested IF
    - ("Valuer") Set Alterable Value B to 1
    
    *(IfElse2)Nested Else 0
    - ("Valuer") Set Alterable Value B to 0
    I hope I haven't made any mistakes while I was rewriting. :P

    The following code works only in specific case. It depends of position when going into the cuboid. While I'm trying going to one wall, it works, but when going into different wall it just holds both camera X and Z.

    Could you help me and fix the "code" above?
    Thanks.

  4. #4
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    I may have a solution,

    Your code is not in reverse polish notation..

    "Z("OpenGL Camera") + Cos(Yaw("OpenGL Camera")) * 2 > Z("OpenGL MS3D") - 12"

    should be

    "Z("OpenGL Camera") + ( Cos(Yaw("OpenGL Camera")) * 2 ) > Z("OpenGL MS3D") - 12"

    Also;
    For 3D movement Including elevation try the following

    X position = X position + (Sin ( Y Angle [Yaw] ) * Sin ( X Angle [Pitch] ))
    Z position = Z position + (Cos ( Y Angle [Yaw] ) * Sin ( X Angle [Pitch] ))
    Y position = Y position + cos ( X Angle [Pitch] )


    Maybe a screen-shot ?

  5. #5
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2007
    Location
    Poland
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    Thanks for the reply. Unfortunatelly it doesn't solve my problem.

    Here, check my mfa.
    http://www.speedyshare.com/files/28012287/OpenGL.mfa
    For now it's poor, I'm just trying to finish engine and when I do it, I'll try to finish game.

    I also translated whole comments from polish to english to understand it better.

    The problem is, when player touch a wall, he will be stuck there.

  6. #6
    Clicker Multimedia Fusion 2

    Join Date
    Sep 2007
    Location
    Poland
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    Ah, I have fixed the problem right now and it works great. Thanks SEELE for helping me.

  7. #7
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: OpenGL, 3D game and collision with wall

    I thought you might, the code you uploaded was impressive, and quite close too working

    ***and even written without any access to direct OpenGL commands for example via scripting extensions such as Xlua;

Similar Threads

  1. OpenGl ? how to get all opengl extensions?
    By warlords in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 26th May 2016, 10:57 PM
  2. Platform Game: Overlapping the Wall
    By FlinkGigitty in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 15th August 2010, 12:32 AM
  3. Bouncing object avoids collision (past wall)
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 26th May 2010, 05:07 AM
  4. I need a WALL to be a WALL
    By Lyrikz in forum Multimedia Fusion 2 - Technical Support
    Replies: 13
    Last Post: 18th October 2007, 12:14 PM

Posting Permissions

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