Menu

TWalkCamera gets stuck at tiles

EugeneLoza
2015-08-26
2015-09-18
  • EugeneLoza

    EugeneLoza - 2015-08-26

    Hi, Michalis!
    Again I'm having troubles with 3D tiled map. I build a random-generated map from 3D tiles in X3D files. But TWalkCamera (TPlayer also) gets stuck not letting me out of a single X3D tile through passage... while often clips through walls.
    I've tried to localize the problem as much as possible to minimal in the example.

    The normals seem to be fine.
    No problem with preferred height either (and if those would be, myscale would fix them). However, I think the camera/player should 'fall' to the preferred height, but it is z-locked at the z it is created at.

    There are absolutely no problems in case the Tiles are generated by code.

    Maybe I initialize/add the tiles in a wrong way?

     

    Last edit: EugeneLoza 2015-08-26
  • EugeneLoza

    EugeneLoza - 2015-08-26

    Seems to be I've missed the part "spatial" and "processevents" at scene creation. Seems a little buggy, but now it works.

     
  • EugeneLoza

    EugeneLoza - 2015-08-26

    Yeah... everything works perfectly now.

     
  • EugeneLoza

    EugeneLoza - 2015-08-26

    And a little problem: I set player.camera.FallingEffect:=false; but, as seen in the video, the player still leans to side when moving down the slope...

    Plus another problem: When FPS drops, the player.Camera.MouseLook:=true; seems to lag behind. The control becomes not not intuitive. I.e. when I move mouse the same amount I get different rotation angles when I face different sides of the maze (e.g. smaller angles with lower FPS). On the other hand, keyboard movement is in sync.
    Are there any options to get MouseLook in foreground like the keyboard for more natural contros?
    (UPD) OR... Mouse lags when I do simultaneous movement & rotation.

     

    Last edit: EugeneLoza 2015-08-26
  • Michalis Kamburelis

    TWalkCamera (TPlayer also) gets stuck not letting me out of a single X3D tile through passage

    As you found out, the collisions are done with the whole scene bounding box (default T3D class implementation of collisions), unless you set "TCastleScene.Spatial" to build an octree.

    Note: The normals orientation (you mentioned them) have no effect on collisions --- right now, faces are always collidable from both sides, or not at all, in all our collision code. So, when solving collision problems, don't worry about normals, they don't affect how the collisions in our engine works.

    I set player.camera.FallingEffect:=false; but, as seen in the video, the player still leans to side when moving down the slope...

    That's weird, I would have to see the code --- setting FallingEffect:=false should definitely turn off this effect.

    https://www.youtube.com/watch?v=nwywK8eegQc

    Way cool!

    Can I post about it on FB / G+?:)

    When FPS drops, the player.Camera.MouseLook:=true; seems to lag behind

    Unfortunately, mouse look depends on the constant stream of "mouse move" events from window system. If the window system is busy (e.g. because the game has low FPS), mouse look will lag. I don't know of any way to make it (much) better... Keys handling works another way, because once we get "key down" we know that the key is pressed until we get "key up". So key processing doesn't involve a lot of events from the window system.

    Note: if your maze is constructed from many TCastleScene instances, you can optimize it in a couple of ways:

    • To reduce memory usage, you can place the same TCastleScene instance many times within CastleControl1.Scenemanager.Items, all under different T3DTransform.

    • To make speed really better, combine all your TX3DRootNode instances into one TX3DRootNode. That is, create one new TX3DRootNode to keep them all, and for each scene add it's TX3DRootNode (wrapped in TTransformNode) to that single TX3DRootNode. This allows you to load whole maze into TCastleScene, which will make stuff faster --- octrees (used for collision routines and frustum culling) will work Ok. Right now, we have an octree only inside each TCastleScene, so it's not optimal to have thousands of TCastleScene instances with collision detection.

    • For even more speed (but that will possibly not be needed) you could "bake" various combinations of some tiles into a single Shape, and then arrange larger Shapes. That is, Shape with just a few walls is not optimal. Right now, the engine doesn't combine shapes for rendering automatically.

     
  • EugeneLoza

    EugeneLoza - 2015-08-27
    Can I post about it on FB / G+?:)
    

    Yes, of course, if you see it fit.

    That's weird, I would have to see the code --- setting FallingEffect:=false should definitely turn off this effect.
    

    Code attached. The player.camera is set up in formcreate.

     
  • EugeneLoza

    EugeneLoza - 2015-08-27

    And compiled version with assets https://www.dropbox.com/s/v4czrwpo9n2hyqb/Mazer3%20-%20150826-2.zip?dl=0 (assets are very poor quality... I've made just a sketch to test the generation algorithm)
    Made some minor gameplay: to find a rose in the dungeon.

     
  • EugeneLoza

    EugeneLoza - 2015-08-27

    About the mouse lags... It really seems not FPS but keyboard to hinder the mouse. I.e. when I move I cannot rotate the view. To rotate normally I must stop.

     
  • EugeneLoza

    EugeneLoza - 2015-08-27

    And another relative question about camera. The documentation states that if I bump the camera into the wall at <90 degs it slowly slides to the side. But in the game 'bumping the wall' always locks the player moving in this direction. Can I make sliding the walls (i.e. if bumped into a wall, then (not very slowly) slide along)?

     
  • EugeneLoza

    EugeneLoza - 2015-08-27

    (moved to new topic)

     

    Last edit: EugeneLoza 2015-08-28
  • EugeneLoza

    EugeneLoza - 2015-08-28

    Update on mouse: I've tried the FPS game example and keyboard+mouse work flawlessly. Maybe this is CastleControl-specific problem?
    Reduced the number of tiles.
    ~600000 tris scene = awfully low FPS
    ~150000-200000 tris scene = mouse lags awfully but playable.
    ~20000 tris scene = mouse lags.
    ~2000 tris scene = mouse moves almost smoothly (thou not ideal), but lags at 'going up the slope' and seldomly at other moments.
    Maybe a kind of frameskip might help? i.e. give the priority to controls not to rendering. E.g. keyboard works fine for all cases, except when FPS gets below 10.
    I'll check Linux today. And, maybe, there's some point to try CastleWindow instead of CastleControls.
    (UPD) Mouse lags when TImage minimap lags also. There seems to be problem with Lazarus form update lag to grab the mouse only each update.
    (UPD2) Linux test: The mouse lags when the player moves. But does not lag at low FPS! I.e. when the FPS is low the mouse rotates normally even if the program draws once per 30 deg and its position is predictable. But when I move forward or strafe (keydown and no keyup) the mouse does not respond or responds very badly.
    However, very low FPS sometimes causes unpredictable results in case 'drawing' is once per 90 degrees and worse (i.e. quick rotation at ~5 to 10 FPS). It results in up to 2x 'more than expected' rotation angles (e.r. almost 360 degrees instead of 180).
    (UPD3) On Win7 sometimes it is possible to 'drag' the mouse out of the gamescreen as if the program is in the background. However it becomes locked as soon as the cursor is back in the CastleView boundaries.

     

    Last edit: EugeneLoza 2015-08-28
  • EugeneLoza

    EugeneLoza - 2015-08-28
     

    Last edit: EugeneLoza 2015-08-28
  • EugeneLoza

    EugeneLoza - 2015-08-29

    I've rewritten the program for CastleWindow and there is no mouse lag. It's problem of CastleControl/Lazarus forms.

    However, mouse movement is not smooth in contrast to keyboard movement.

     

    Last edit: EugeneLoza 2015-08-29
  • Michalis Kamburelis

    I set player.camera.FallingEffect:=false; but, as seen in the video, the player still leans to side when moving down the slope...

    Ah, I see the problem. TPlayer.UpdateCamera overrides Camera.FallingEffect every frame.

    To fix this, I added a new property TPlayer.FallingEffect, here: https://sourceforge.net/p/castle-engine/code/14674/ . You can update to latest engine SVN to have this. In your code, change "player.camera.FallingEffect:=false" to "player.FallingEffect:=false".

    This is not a nice solution, but I see no way around it... TPlayer deliberately controls the camera underneath, overriding various properties of it. By design, it sets various camera properties, based on whether player is dead, whether player is underwater and so on. The "cleaner" solution would be to just hide the Camera property (actually it's in T3DOrient class), but this would be very limiting then, we would need to expose a lot of TCamera/TWalkCamera interface then through TPlayer class. Better ideas for API are very welcome here:)

    About the mouse lags... It really seems not FPS but keyboard to hinder the mouse. I.e. when I move I cannot rotate the view. To rotate normally I must stop.

    I see that you're using Lazarus TCastleControl. Unfortunately, mouse look always had problems under Lazarus, because Lazarus event processing is not prepared to handle mouse events smoothly when it's event loop is clogged... We do try to work with it anyway (see a looong comment at TCastleControlCustom.MouseMove implementation), but it's impossible to make it perfect.

    This doesn't happen in TCastleWindow.

    Unfortunately, so far I did not find any solution to make mouse look always smooth with Lazarus --- sorry... The only solution is to probably submit appropriate patches to Lazarus. But it's not easy, as both WinAPI and GTK (at least) have (different) problems.

    I see in later post that you have found this already. Lazarus+GTK event loop also has problems when it's overwhelmed with events (mouse look), but different from Lazarus+WinAPI.

    BTW, I'm running your game on Linux, combining the sources + assets you provided. Works like a charm:)

    But in the game 'bumping the wall' always locks the player moving in this direction. Can I make sliding the walls (i.e. if bumped into a wall, then (not very slowly) slide along)?

    Wall sliding is done automatically. And in my tests, it kind of works in your game --- but indeed it's far from perfect, in many cases movement is stuck instead of wall-sliding. Most probably a problem in code, I'll see if I can make it better, will let you know!

    Maybe a kind of frameskip might help? i.e. give the priority to controls not to rendering. E.g. keyboard works fine for all cases, except when FPS gets below 10.

    Not sure if it would work... Right now, as soon as we have an event from the window system, we immediately process it. We process all the events before doing render+OnUpdate (see castle_game_engine/src/window/castlewindow_winsystem.inc), to not get "clogged" by inputs. Without changing our code to use threads, the only thing we can do to capture more events is to just abort rendering some frames, to process more events in the meantime. (Ok, I understand that this is exactly what you mean by frameskip?)

    But this means that when our FPS is low, we make it even smaller...

    (UPD3) On Win7 sometimes it is possible to 'drag' the mouse out of the gamescreen as if the program is in the background. However it becomes locked as soon as the cursor is back in the CastleView boundaries.

    It is actually possible on any OS, if you have low FPS and game runs in window mode. It's a problem because (right now) we do not "lock" the cursor better, we only shift it back every frame to the middle of the window.

    I've rewritten the program for CastleWindow and there is no mouse lag. It's problem of CastleControl/Lazarus forms.

    Cool:) I see you have already found out what I mentioned --- Lazarus event loop causes mouse look to always stutter. TCastleWindow works cool here (at least as long as you have enough FPS).

    However, mouse movement is not smooth in contrast to keyboard movement.

    You mean, at low FPS, mouse movement is still not smooth? That's to some extent unavoidable --- see my first reply.

    At high FPS and TCastleWindow, mouse movement should be 100% smooth.

    Sorry, I realize that some of the answers are along the lines "unfortunately, I don't see how we can improve things here". Unfortunately, low FPS wil cause problems with input processing, which is especially felt by input-intensive mouse look. I would rather fight and make FPS higher:)

     
  • EugeneLoza

    EugeneLoza - 2015-08-31

    Thanks for the answer!!! I'll try to work with it today...
    Latest video :)
    https://youtu.be/aYq4KGaLKE8

     

    Last edit: EugeneLoza 2015-08-31
  • EugeneLoza

    EugeneLoza - 2015-08-31

    Made a github with the latest version: https://github.com/eugeneloza/Mazer (and a release for Linux).

    I added a new property
    

    Thanks! I'll try to implement this asap.

    Wall sliding is done automatically. And in my tests, it kind of works in your game
    

    Very strange... because in my compillations both in Linux and Windows there is no wall sliding at all. I just bump into the wall and become locked until angle is out of the wall.

    Most probably a problem in code, I'll see if I can make it better, will let you know!
    

    Maybe just point me where to start looking. I'd want to try to implement a little bit another logic (for more action). To make the combat more dynamic and inertial (as soon as I implement it).

    see castle_game_engine/src/window/castlewindow_winsystem.inc
    

    Thanks, that's exactly where I should start I guess.

    At high FPS and TCastleWindow, mouse movement should be 100% smooth.
    

    Yes, indeed it is. But still, I'll have to think about making it better. There seems to be a rather simple way around in dynamics/inertia for rotations. Maybe merging 2 frames at render... But that'll require for me a lot of time to grasp.
    I.e. in FPS-like games it's fine not only due to high FPS, i.e. I sometimes have a (very) low FPS at TES Oblivion, but still there is no problem even for ~5 FPS to control the character, while in Mazer ~15 FPS break the natural (smooth) look.
    I'll think about it.

     
  • EugeneLoza

    EugeneLoza - 2015-08-31

    Made a FPS counter to find out a result: when I move i get ~25 FPS (rather old computer with Linux), when I rotate I get ~5 FPS... Maybe that's correct... but seems to be strange.
    (UPD) Even more strange... The behaviour is absolutely different at Win7... 60 FPS at movement and ~100 FPS at rotations, while the screen still flickers. Motion blurl...?

     

    Last edit: EugeneLoza 2015-08-31
  • EugeneLoza

    EugeneLoza - 2015-08-31
    To make speed really better, combine all your TX3DRootNode instances into one TX3DRootNode.
    

    I've looked through a documentation for the TX3DRootNode, but I found no way to do so... Should this be something like 'children.add'?
    I have an idea of splitting the scene into multiple chunks (i.e. to get almost unlimited amount of chunks with no FPS or memory issues). But still not very sure how to...

     
    • Michalis Kamburelis

      I've looked through a documentation for the TX3DRootNode, but I found no way to do so... Should this be something like 'children.add'?

      Yes, exactly. I added an example code demonstrating exactly that to the engine, examples/3d_rendering_processing/combine_multiple_x3d_into_one.lpr , http://svn.code.sf.net/p/castle-engine/code/trunk/castle_game_engine/examples/3d_rendering_processing/combine_multiple_x3d_into_one.lpr :)

      As for the wall sliding problems mentioned in this thread, I still have it on my TODO list to improve:)

       
  • Michalis Kamburelis

    P.S. To make the textures less blurry in the distance, you can try using anisotropic filtering. Simply edit your X3D files and change

    <ImageTexture....
     />
    

    into

    <ImageTexture....>
      <TextureProperties anisotropicDegree="2"/>
    </ImageTexture>
    

    You can try using larger values for anisotropicDegree, like "4" or "8". But be careful, this will hurt FPS (although the raise in quality will be visible).

    See X3D spec of <textureproperties> http://www.web3d.org/documents/specifications/19775-1/V3.3/Part01/components/texturing.html#TextureProperties , and see wikipedia https://en.wikipedia.org/wiki/Anisotropic_filtering to know how it actually works:)</textureproperties>

    Right now using this requires editing X3D file (that I see you generate from Blender), or doing the equivalent X3D transformation by code at loading (which is possibly more trouble than the feature is worth...). I hope to improve http://castle-engine.sourceforge.net/creating_data_material_properties.php one day to be able to specify anisotropic filtering outside of X3D files, in simple XML.

     
  • EugeneLoza

    EugeneLoza - 2015-09-17

    combine_multiple_x3d_into_one.lpr :)

    AWESOME!!! It's working like a charm!!! At least tripple FPS.

    MOREOVER - The player slides around the walls now :) Fantastic :)

     

    Last edit: EugeneLoza 2015-09-17
    • Michalis Kamburelis

      Great!:)

       
  • EugeneLoza

    EugeneLoza - 2015-09-18

    Latest release https://github.com/eugeneloza/Mazer/releases/tag/v.150917-1_Win32%26Linux with anitotropic smoothing & normal map (still dot3product).

     

    Last edit: EugeneLoza 2015-09-18
    • Michalis Kamburelis

      Fantastic (and fast!):) Tested on linux 64-bit.

       

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB