1

I'm making a 3D game, and looking at the best method to have a floor plane as part of the 3D. If you imagine those games like TempleRun, but no turns, where you are moving forwards and the floor is scrolling backwards (towards the user) infinitely.

I already have my 3D object moving around X axis suitably (on a fixed Z plane), but now looking at adding a background, floor, etc.

I've been reading on Decal and Plane but uncertain as to which would be the best approach. I'd have the same floor structure on each level, but with different textures. Does one offer more expandability in the future? Eg, slopes, hills, etc. Each floor structure (whether Decal or Plane) would be repeating endlessly, and I'd see if I can create a fog effect which makes the floor fade with distance. Also it would have a tileable texture (eg grass, tarmac, dirt) which would be repeating backwards.

Perhaps even a static structure, and simply move the texture backwards?

Any thoughts would be great, thanks.

Jammo
  • 1,838
  • 4
  • 25
  • 39

2 Answers2

2

I would say don't go with decals, as these don't react to libgdx's environments (lights, shadow, an so on). And a Plane is just some class that represents plane and can't be rendered at all.

Simples solution: go to blender or any other 3d editing tool of your choice create a plane and apply your tillable texture to it.

Export it as .fbx and convert it to .g3db (libGDX's format).

Load it into your game and and make a couple of copies of it (ModelInstances). Place those on the floor one after another so that no gap appears and they all form a nice repeating ground.

As your character moves forward check its position on X axis (or whatever axis you want to move on) and if the position is greater than position of your last plane on the floor - some distance than update floor as follows:

Remove the first plane from ground and add it after the last plane that you have.

(Render everything with ModelBatch)

If you have enough of these planes the player wont notice them appearing in the distance. Also use fog to completely hide this transitioning of planes.

The same can be applied not only to planes but repeating hill or any other tillable 3d object.

  • Thanks for the note to avoid decals because of lighting etc; useful. I've gone with creating various instances of a textured rectangle – Jammo Apr 04 '14 at 14:28
  • Nice answer. You have added everything i forgot to say. +1 for that – Robert P Apr 04 '14 at 14:31
1

You could have some Planes made with meshpartbuilder (Like explained here) or even a Model made with an Application like Blender.
As you can create many ModelInstances out of one Model and give them different Materials, you can use the same Model over and over again. So you could create a 4x4 meter (for example) big Model (it will only be 1 face) on the XZ-Plane. Next you create, lets say 10, ModelInstances out of it and add them to each other:

  • first Plane: x = 0-4m, y = 0-0, z = 0-4m
  • second Plane: x= 4-8m, y = 0-0, z = 0-4m

And so on. As soon as your character is at a X Position > 4, you can translate the ModelInstance firstPlane foreward to the end of the 10th plane. So its new x would be 44-48 meters.
As soon as you reach a new level or another ground or whatever you can simply change the Material of the ModelInstance.
For the background i would suggest to read something about SkyBoxes.

Hope i could help

Community
  • 1
  • 1
Robert P
  • 9,398
  • 10
  • 58
  • 100
  • Actually this works great. I have 10 instances now, and when they go behind my character, I `thisModelInst.transform.trn(0, 0, z)` translate it back into the distance onto the end of the "stack". Just need to look at how wide to make it now (maybe walls on some levels, or maybe just a wide floor), and then distance fog. Thanks for your help – Jammo Apr 04 '14 at 14:27
  • The `Wall`s would be more or less the same. Actually they would by faces on the XY Plane (or ZY depending in which direction you go). Also the idea with the Fog is good, so you can hide the transition. If you stil can see the transition, you can increase the number of `ModelInstance`s until the performance goes to low. You could even add a `Setting` for the render distance (number of `ModelInstance`s). Just to give you some ideas. – Robert P Apr 04 '14 at 14:36
  • Yep, for walls I'll use the same method described above. For "open areas" I'll just extend the floor sideways. This might need a separate question, but as for the fog, is there anywhere you can recommend on how that is done? searching libgdx and fog isn't yielding much. It seems the functionality was removed from a previous version and there is a different, more modern, way to do this now? – Jammo Apr 04 '14 at 15:15
  • As much as i remember you only need to add a `ColorAttribute` with the type `ColorAttribue.Fog` to the environment. (http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/attributes/ColorAttribute.html). The default Shader takes care about this Fog attribute, as much as i remember but i am not sure. And i stil use the version 0.9.9 of Libgdx idk if it changed... – Robert P Apr 04 '14 at 15:25
  • Yeah I was playing with that with no luck, then Xoppa mentioned it was my cfg.useGL20 = true. I had False originally. Now works perfectly :) – Jammo Apr 04 '14 at 16:03
  • @Jammo ah okay. Yea you need at least GL20 for that. – Robert P Apr 07 '14 at 05:55