megatronx's Forum Posts

  • R0J0hound

    I have a question, but actually re another subject. I have a problem figuring out how to do something with bitwise auto tiling and diagonal tiles. SO I have those diagonal tiles, which half is of a tile type, and another needs to be selected according to neighbouring tiles of another type, and I can't figure out how to do it, so If you have any suggestions it will be appreciated.

  • Now, I could translate correctly, you are having issues with player Z colliding, right? In my template I did the way Construct 3 3D Platformer Template did and it's working pretty well. But I think you can also make Z collisions with Height map, you pre-render the map outside Construct 2 and get it's height map, and use some javacript or a plugin that can read colors, then you detect what Z Elevation the player should be depending on the Z Map Height.... It's hard to explain... did you get it?

    Sure, but if you read my response to ROOJ you'll see what I'm after. And for the terrain Z I'm using noise+tile type :)

  • megatronix

    Always nice to hear the plug-in being used. Time and motivation are the main obstacles of most of my projects. But anyways.

    I’ll look up that program. There’s always interesting ways different programs do things.

    Which load action? There’s one to load an image file, one to grab a sprite texture and one to load an obj file. Obj files are a simple text based 3d model format. You could probably generate a file from the vertices. Just save the xyzuv of the vertices to an array as you add them. Then you’d add two lines for each vertex in the file: “v x y z”&newline&”vt u v”&newline. Then you’ll need to add the faces. Every three vertices define a face so this would generate the face data:

    Var i=0
    Repeat int(vertexCount/3) times
    — set i=loopindex*3+1
    — append “f “&(i)&”/“&(i)&” “
    — append (i+1)&”/“&(i+1)&” “
    — append (i+2)&”/“&(i+2)&newline

    Collisions are a can of worms. Storing all the xyz’s of the vertices is the first step. Then if you transformed the object using that mesh at all you’ll need to transform those points too. Basically xyzVector *scaleVector *orientationMatrix+positionVector. After that, each group of three vertices define a triangle. And after that… I guess it depends on what kind of collision detection you want. There are a lot of algorithms different algorithms and I can’t do them justice off the top of my head. Tri vs Tri could be done with SAT, MPR, GJK or maybe calculating the line where the two planes making up the triangles intersect, clipping the line by the edges of both triangles and if there’s anything left it’s a collision. Those first three algorithms work with all the points of convex solids and will give some collision info such as normal vector and where.

    I don’t think I’m scratching the surface though. In general to make things faster you’d use a simpler collision mesh instead of the visual one, or approximate it with simpler primitives like spheres, bounding boxes, oriented boxes, capsules, height maps etc. However in the construct realm I think the simplest solution is just do all the collisions in 2d and have the 3d just be a visual. You can look at any 3d collisions people are doing in c3 for some ideas too.

    The process for implementing any of that is to find an algorithm online somewhere and adapting that to events. I can only give an overview here atm.

    Thanks for extensive reply. Your plugin is very cool addition to c2. Shame it is not completed, but I decided some time ago that I will just make what I can within its limits.

    Currently, since I am currently developing tile system for tile map use, my plan for collisions is to simply check neighbouring tiles and based on that place temp wall sprite tile here wall tile is. However, I was thinking of dropping this idea and replacing it with proper polygonal collision based on vertexes. Then I could use tilemap only for world creation. I will get back to the subject once I get to that point.

    I also would like to implement 2 shading features using vertex coloring: 1. AO, and 2. Static shadow system. The shadow implementation in the plugin is unfortunately not working as intended, so alternatively I am thinking of making my own simpler system. But I do think calculation pre drawing the polys would have to use the Array too since the system would have to reference other tiles being in the direction towards the light source. Although maybe this could also be done just with tile map I'm now realizing, thought somehow would have to consider the foliage and other elements on the map that would be spawn using noise values. But any thoughts on that?

    As for mesh building, I actually went with a simple system where I have a set of frames with image points. I place the sprite on a tile, set its parameters according to the tile and then just draw tris once after another using imagepoints. Its pretty good solution. But should work faster once the vertexes are being read from an array.

  • Hey MegaMente Br

    I did some work in project and I had an idea: Do you think it would be possible to "update" the plugin using any AI Bot for programmers? I will ended trying anyway, but because I have almost no knowledge in javascript I just wanted to ask you... :)

    P.S.: I think the "Template for 3D" project it's half way there, and I think with this template it will even possible to recreate games like Fall Guys, Fortnite and Minecraft... (but those games would be almost be a voxel-style game with custom 3D objects)

    I mean, I am having a bit of issues with optimization, but I am positive about it.

    Here's a tip. If you have more then 2000 objects loaded you will experience fps problems. Ideally around 1000 objects is where you will keep your performance smooth. So you will have to create an array that will keep positions of all objects in map and then pick from a pool of free objects first free one, tag it as busy and load a mesh in to it and position it. Once it is not in view you can unload the object and place it back in the free pool array.

  • If you want to try an ai coder then go for it. I wouldn't be interested in trying since it would create more work for me to verify made working changes and if it broke it I'm not interested in debugging it.

    I'm happy you've found enjoyment in using this plugin, but at this point I'm not likely to revisit it at all. I'm more likely to make a stand alone tool independent of Construct since most of what I want to do in Construct requires workarounds and once I made such a tool I'd probably disappear from here rather quickly.

    I'm using your plugin still. I am in the middle of programming map systems. I agree about the amount of wark-arounds. Those are painful, since many of those systems could have been implemented from the get go. But regardless, with so many years doing prototypes in c2 I've learned it to the degree I am making my own 3d game in free time and I don't want 11 years to go to waste. I'm creating everything from vertexes instead of importing objects. This way I can create large map and save it as single object and enjoy really good performance. But I would love to see your tool, which would borrow the best aspects of construct but would improve on it, add things, and allow to make 3D games easily, have 3d editor, dynamic vertex shading etc. There is a program called Manu being developed. It is very promising but the way you program in it is a bit hit and miss. But check it out.

    I have a couple of questions: 1. I'm thinking of storing each map vertex in 3d array to use it for collisions, but to be frank I have no idea how I'd have to go about it, other then I know I'd have to nest arrays inside arrays for performance sake. Any Idea how to do do vector calculations with that? Or in general how I can calculate a vector from 4 vertexes? 2. Do you remember what LOAD action exactly do in your plugin? I haven't tested it, but I wonder if I create 3d meshes and then download the state of the plugin, will loading that state recreate the meshes, instantly and I won't have to generate them with code?

    Thanks!

  • You mean something like this?

    Repeat 4 times

    — dx= round(cos(loopindex*90))

    — dy= round(sin(loopindex*90))

    Yeah, I'll try that. Thanks.

    Had nearly the same one but without round that's why it wasn't working.

  • It's been and while. I forgot how to check array at -1,0 1,0 0,-1 0,1 with one loop?

    I was using sin and cos but can't get it right. I need to test neighbouring tiles at 0, 90, 180 and 270 deg from the central tile. Help appreciated!

  • Well depending on how you’re doing the noise you will have a function noise(x,y) which you can scale and offset with noise(x*scale+offsetX, y*scale+offsetY), or maybe you’re just setting random values to a 2d array.

    Anyways let’s say for example you want a 2d grid with a point every 32 pixels. Just have a 2d array of z values.

    You can get the nearest point’s z with

    Z = Array.at(round(x/32), round(y/32))

    Or if you want a linear interpolation between the points it would be:

    Z = lerp(

    lerp(array.at(int(x/32),int(y/32)), array.at(int(x/32)+1,int(y/32)), x/32-int(x/32)),

    lerp(array.at(int(x/32),int(y/32)+1), array.at(int(x/32)+1,int(y/32)+1), x/32-int(x/32)),

    Y/32-int(y/32))

    Or something like that. Google bilinear interpolation for other explanations. You can also do bicubic interpolation but that’s more involved albeit gives curved interpolation. Or you could use cosp instead of lerp.

    Anyways, it’s a bit harder to reason about 3d problems from descriptions.

    Thanks for reply. Tried the lerp first, but couldn't get it to work. However went back to original idea using noise value and fixed what was wrong with the function. :)

  • R0J0hound Maybe you could help me with something. I am trying to figure out how to set Z for the characters properly. I was trying to get z it from noise but it's too chaotic for some reson and the camera is going up and and down while moving in quite extreme ways. SO I stored noise peaks in array and atm I am only dividing player x and y by tilesize and then lerping from players z to array z very quickly. But I think that if I'd set players z from quad's 4 Z vertexies it would work better, but I have not much idea how to do that. I think I'd have to check first if player is within that quad with X and Y and Z and then set players Z based on distances to the edges Z's? If you could advice, please do. Best M

  • Glad you’ve found it useful. I’m not currently developing it further. I coded myself into a corner and would need to take time to figure out the best way to rewrite it and I don’t have the same momentum or time to do that at this time.

    Its great little plugin. I just programmed hightmap generator from noise.

    I'd acctually say that more important then 3d physics or animations would be fixing shadow issues, adding another light options for extra lights, and adding more texturing options.

    It would be really nice if this plugin would get updated. Really!

  • Thanks! I will check it ASAP!

    You can use image shaders to trick AA or just render in higher resolution with high quality up scaling and downscaling.

  • R0J0hound Question re MeshTag:

    I don't suppose there is mesh IID or UID, isn't it?

    Would be cool to be able to set up all meshes of same group with single action without loops. Ie: MeshTag: cube, MeshId = 0 - pick all else pick nth.

  • That’s called “broad phase” collision detection. Basically doing approximate collision detections by using a distance check or something. Other ways are using bounding boxes, bsp, quad tree, collision cells, etc. construct already does it somewhat with the overlapping condition.

    Anyways you can do that with events but you’d have to actually do it and test if it improves performance. The overhead of implementing those things with events can often result in things being slower oddly enough.

    Anyways the logic of the distance check you describe could be:

    For each sprite

    For each terrain

    Compare distance between sprite and terrain <100

    Sprite overlaps terrain.

    But with events you already reduce the terrain loop by doing this instead:

    For each sprite

    Sprite overlaps terrain

    For each terrain.

    But that’s mainly because internally construct can filter the objects faster than you can do manually with events which are slower.

    You other idea of adding and removing objects as needed is another idea. But you’ll have to test it. This plugin was made so you only have to make events to update objects you want to move. All the static objects will just redraw fairly efficiently. Adding/loading on the fly would be slower but it may end up being faster in the long run. But you’d have to actually test it out.

    All right, thanks, I'll be testing. I want to streamline the code. My current performance is smooth solid, but it hits 95% to 98% on i78750h with 1050ti and 32gb of hyperx ram. 70% of it are draw calls. Each terrain sprite has 4 meshes attached to it and there are 4 rojo3d plugins on different layers. SO my hope is that I can lower the cpu usage, and with array technique i can lower the number of 3d objects. Will test :)

  • I aim for simple and easy to read with my events if I can. Using arrays to store object info instead of sprites may or may not be better, it just depends on how you want to implement it.

    You can sort arrays, but you can also sort sprites with “for each ordered”, just use the stop loop action when loopindex=0 if you just want the closest. Or use a higher number to do stuff with more.

    The only time I use an array for terrain is if it’s in a grid formation, in which case a tilemap can work too for 2d. If the terrain is different sizes and whatnot I’d just use sprites.

    Not sure I grasp your distance calculation. Would a 3D distance calc work better?

    Sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)

    I have no technical expertise with the fov behaviour. I find behaviours seldom do what I want so I’m more inclined to do stuff from scratch than do things to bend behaviours to my will.

    For your last question I think there’s a misunderstanding.

    You get the position of objects with the x,y and z expressions as I recall.

    The orientXX/Xy...Zz expressions is the orientation matrix of the 3D object. Aka. How it’s rotated.

    You can think of those as three vectors.

    OrientXX/Y/Z is the left vector of an object

    OrientYX/y/z is the up vector of an object

    OrientZx/y/z is the forward vector of an object.

    Ok, cool. Thanks for the answers and 3d distance calculations. I will think of its use for sure.

    But let me elaborate. The distance would be there to first check for objects within radius form the actor, and after that those objects that are near the actor are checked for collisions with it. Atm I'm doing isOverlapping,for each overlapping to test collision with grounds and walls for all actors. But since this is the only top condition to pick and check collisions, my idea is to get rid of those sprites and just test for nearby 3d objects with data inside array and then do radius check if actor is colliding.

    Also the level loading is dynamic, or rather positioning of the objects is based on what is in the level array. If player has LOS to position, I pick idling terrain sprite, then set all of its values from data stored in array, then pick mesh and set it's parameters with values taken from the sprite. I've created level exporter you see. It exports everything in to array. Then I'm applying that data live based on objects XY in the array using LOS. This way I can have big levels with number of sprites under 200. But for each sprite I do need to update 3d mesh, static once, but others like those for actors or liquid and billboards all the time. In this case it feels like sprites are only a middle-man, and could be completely omitted. I already got rid of sprites for billboards like trees etc. But my worry is that 2k objects in array that needs to test against number of actors so that i can select which ones will be testing collisions against might impact performance more then if i have 111 terrain sprites at all times.

    Idea is to narrow it down by first testing which level objects are visible to the player and then put them all in to it's own array and do sorting based on distance and only check collisions for those objects that have distance lower then some value, and stop the loop. And then do the same for other actors in the scene. I imagine this is how its done when picking overlapping objects, with the difference that if the sprite object has collision poly with more points then 4, like in my case my ellipses have 12, that collision check might have same or bigger impact on performance then simple distance check for nearby objects and then testing each for collision with radius from the center of each object.

    Ik this is a lot in realm of theory. I guess I have to try it and if it won't perform well, I will get back to using sprites.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Hi, maybe you cold give me a technical advice?

    My game is moving forward every day, with the method "two steps forward, one step back".

    I'm at the point where I have thought trough stopping using standard sprites (with roughly 12 collision mask points) and instead focus solely on 3D objects with assumption that it will release some of the cpu.

    So far I've been using sprites as a collision detector as well as reference for 3d mesh.

    With collisions the event started like this:

    - for each actor, actor overlapping terrain, for each terrain.

    but since I want to make sprites redundant I am thinking of putting all terrain data in to arrays. So first all level data will be in an array, roughly 2k objects with their data per level, or roughly 200 objects per room in a level. These are terrain object and each of them is a cell contenting Json data with npc's and other things that I load temp array with and place on the map. Checking if their are active can be done trough var change in an array. but I'm also considering having another array just with id's and distance to npc, so that I can sort it quickly according to distance and stop loop if distance is greater then a value.

    Here are my doubts come in:

    - if I sort array with 100 entries (if I use active objects array) or 2k entries ( if I do all checks inside map array), then check distance up to a certain distance and then pick those objects and do my collision code ( which is ellipse radius calculation done twice, once on xy plane and another on plane created by calculated radius and z to calculate z to place object on. Also first radius calculation is used as collision with walls if player is below floor range). Will that work as good or better then using LOS plugin to check x'y in one of the arrays, or work as good or better then checking overlapping with sprite? And how would that work if I had 40 npcs needing to check their surrounding to see if they are colliding with anything?

    Also, the checks are spread across several ticks with counter, so if counter is 1 I do this and that, and then counter = 2 and so on. Obviously that is necessary.

    Also, if id go with that, which 3D object position property would be mirroring of a sprite. Would that be XX, YX, ZX or XX, XY, XZ? I don't understand why there is so many variants for position in 3D, please explain.

    Best

    M