R0J0hound's Forum Posts

  • Best I can tell there isn’t a way to select between mono and stereo recording in construct. You’ll have to use JavaScript to do it at a lower level. It has nothing to do with construct at that point. In fact construct may just add some complexity to do it.

    Google is your friend to find examples of maybe some libraries that handle that.

    Best I can tell it involves requesting access to the microphone, creating a web audio context with stereo, use the microphone as a source, that sends chunks of raw audio to an array. Then use a library or something to encode it as some sound format.

    Doable but could take some time to do. Best case you’ll find some code you can drop in and use.

    I’m a fan of trying to find a way to do stuff. But you have to weigh the effort to do it vs shifting to a different idea.

  • I think that’s an artifact with how the perlin noise is calculated. It’s kind of hard to google info about it. According to the description of the algorithm on Wikipedia I can see a part of the calculation which will make the result tend more to a midrange value. If you implemented the algorithm with events you could correct that but I’m not sure if it would affect the look of the noise in an adverse way.

    From what I read, traditional perlin noise causes most values to be in the -0.7 to 0.7 range. But if you change that to the 0-1 range you get values like you’re testing.

    One thing you can do is scale the noise to be closer to the 0-1 range. Something like this:

    ((Noise(x,y)*2-1)/0.75)/2+0.5

    It converts it to the -1 to 1 range, scales it by 0.75 then converts it back to the 0 to 1 range.

    The 0.75 comes from your max value of 0.85. (0.85-0.5)*2=0.7 but I just used a slightly higher value.

    There’s also different way you can scale it. Using an exponent you can push values from the center.

    Value= Noise(x,y)*2-1

    Value= sign(value)*abs(value)^0.3

    Value= value/2+0.5

    The 0.3 is a bit arbitrary. But no matter the value you won’t get a result out of the 0 to 1 range.

    The way you calculate the min/max works too. You just don’t have to do that every time your games runs. The values you get will hover around the same thing for each noise type. So you can find those once outside your game and just use those values to normalize your game. You can then clamp that too if you have outliers.

    Clamp((Noise(x,y)-minValue)/(maxValue-minValue), 0, 1)

    You asked about simplex noise but I imagine that has the same quality as perlin. You could also do smoothed noise and get a perfect 0-1 range, it just looks more grid like.

  • Hi,

    Had a look and no, I'm not wrapping my head around it. I just see a lot of shuffling going on.

    Based on this whole thread you are doing three things: shuffling, shuffling using a specified order, and displaying the numbers.

    function shuffle(text)
    -- var i=0
    -- repeat 10 times
    -- -- set i to int(random(4))
    -- -- set text to left(text, i) & mid(text,i+1,10) & mid(text,i,1)
    -- return text
    
    function shuffleBy(text, order)
    -- var ret=""
    -- repeat 4 times
    -- -- add mid(text, find(text, loopindex), 1)
    -- return ret
    
    function display(text, x, y, anim)
    -- repeat 4 times
    -- -- create sprite at (x, y+32*loopindex)
    -- -- sprite: set frame to int(mid(text,loopindex,1))
    -- -- sprite: set animation to anim

    I can't follow all of what you're trying to do but everything can be done with those building blocks. Notice the display just creates the sprites. Just delete the old ones first.

    I the case of one of your first example. You have a number, it's then shuffled by one of three unique choices, then it's shuffled by another value and you get a result.

    var A = shuffle("0123")
    var B1="",B2="",B3=""
    while B1==B2 or B1==B3 or B2==B3 
    -- B1 = shuffle("0123")
    -- B2 = shuffle("0123")
    -- B3 = shuffle("0123")
    var correctB = choose(B1,B2,B3)
    var C = shuffle("0123")
    var answer = shuffleBy(shuffleBy(A, correctB), C)
    
    //display
    display(A, 100,100, "alpha")
    display(B1, 100,100+32*1, "digits")
    display(B2, 100,100+32*2, "digits")
    display(B3, 100,100+32*3, "digits")
    display(C, 100,100+32*4, "digits")
    display(answer, 100,100+32*5, "alpha")

    Beyond that all I can gather from your other posts is you have additional steps added. Here I just had the display create the objects on the fly but you can have it pick existing objects instead.

    I'm not sure if any of that is helpful. I'm going to have to take a break from this problem though.

  • 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.

  • I appreciate the offer but I’m a bit pressed for time lately. No coffees needed. I’m actually considering getting rid of that since I’m happy to help as I have time usually. I can try to have a look again one of these days. It’s just not a fun problem to work on and I’ve created more work for myself since I haven’t been able to create something that is easy to understand or use.

    I burn out on projects pretty quick, even the ones I enjoy. But I’ll see if I can get a chance to look at this again later.

  • Currently that can only be done at edit time.

  • 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.

  • One way is with a direction vector.

    Subtract one object’s position from the other and normalize that.

    DirX=Ax-bx
    DirY=ay-by
    Dirz=az-bz
    Length=sqrt(dirx^2+diry^2+dirz^2)
    Dirx=dirx/length
    DirY=diry/length
    Dirz=dirz/length

    I’d recommend reading some tutorials about vector math. It’s useful for 3d stuff even if you just learn the basics.

    There are other ways to define angles in 3d: spherical coordinates, axis angle, 3x3 matrices, quaternions. They all have their uses.

  • Shaders in construct are limited in what you can access. So you can't access additional textures currently unless they update it in the future. Best bet would be to add the idea to the suggestion platform and hope it's picked up.

    According to the manual:

    construct.net/en/make-games/manuals/addon-sdk/guide/configuring-effects

    That page lists what you have access to from an effect. Currently the two textures you can have access to are the foreground and background. Maybe with some trickery you could have two sprites stacked and use the backgound samper to get the image below. However that has a lot of cases it probably wouldn't work well.

    An unsupported way would be to use webgl directly but that can be tricky/kinda unsolved for C3. Construct's renderer uses webgl behind the scenes currently, with a focus on batching things for speed. In construct 2 I found that you could end all the current batches and then use any webgl you wanted for maximum flexibility. The only caveat was you needed to make sure the webgl state was unchanged when you finished the webgl code otherwise it would break construct's renderer.

    Construct 3's renderer has been reengineered and updated a few times so it's less clear how to utilize custom webgl, if at all. Last I looked it's setup in suck a way to be more of a black box that you can only interact with in a supported way. Also I believe they plan on utilizing a different api later on, and I could see them reworking the renderer in the future, so that would make any unsupported solution easy to break.

    Anyways if you want to attempt it you'll need a few things. First you'll need to access the webgl context of the canvas. There may be something in the js sdk that provides that or you can attempt to grab it from the canvas itself. Next you'll need to access the compiled shader program for your effect. That's probably the biggest roadblock as that might be hidden behind some closures in construct's renderer. Also even if you can find a list of shader programs in the renderer it may still be an issue of figuring out which one it is.

    Anyways, if you're able to find a way to access your effect's shader program then something like the following might be a way to set a second texture you can access from the effect.

    You'd add this line to your effect:

    uniform sampler2d texture2;

    Then to make that reference a texture you'd need to do something like this:

    function setTexture2(gl, program, texture)
    {
     var u_tex2Location = gl.getUniformLocation(program, "texture2");
     gl.uniform1i(u_image0Location, 4); // texture unit 4.
     gl.activeTexture(gl.TEXTURE4);
     gl.bindTexture(gl.TEXTURE_2D, texture);
    }

    You need to call that function with the webgl context, the shader program of your effect, and the handle to a webgl texture. The texture is either loaded with wegl or you somehow access another texture from a sprite or something. The most fragile part here is I'm assuming that texture unit 4 isn't used by construct's renderer so we take advantage of that by using it. You'd only need to call that function when we want to change the texture.

    Other potential issues that may need to be dealt with is how that will sync with the renderer. There may be other issues I'm not thinking of.

    Overall I generally just try to work within what features construct provides, but there are other potential solutions, they just don't always pan out.

  • It’s a project property. I think it’s called image filtering or sampling or something like that. By default it’s linear but you want nearest. I think you may be able to change that per layer but I’m not sure.

  • You could set the camera angle to mouse.x or something. I’m guessing you might have something else in mind but I’m not sure.

    I know there are examples elsewhere on the forum of setting the 3d camera in different ways that could be adapted I suppose. However in this example I’m only supporting setting the camera with the look at action.

  • Here is an update that changes the view from the camera object's position and angle and looks down a bit. Also added some controls to move rotate and strafe.

    There are many ways to set it up so I just picked one and went with it.

    dropbox.com/s/r4g7r0x6ty782zx/cube_raycast2.c3p

  • I just replicated the “look at” action. If any of the other actions that move or change the orientation of the camera are used then they would need to be replicated too.

    Currently the orientation is a 3x3 matrix stored in three sprites. It can be rotated by multiplying with a rotation matrix that rotates the amount you want to rotate. In practice we’d use some simplification of that.

    Another way that may be simpler would be to only use the “look at” action to orient the camera. Just change the look at target.

    X: camera.x+100*sin(a)

    Y: camera.y+100*cos(a)

    Z: camera.z

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I mean there are only two speakers so the volume is balanced between those two for any direction. Option two seemed simpler when I wrote it. I tend to try that a lot. When construct doesn't have a feature I try to calculate it manually and then somehow work that in to the available features.

    You can probably get some basic overview on how to use JavaScript in construct with a few of the tutorials available. There are lots of ways and none of them seem very clean to me. Anyways, the meat of using the webaudio api to do the audio is to setup a node graph. Rough overview of how it would look is this:

    source1->gain->position--+
    source2->gain->position--+->listener->gain->output
    source3->gain->position--+

    Basically any sound you want to play would need to be added to the graph with a gain node. Then they could be removed as they finish. Of course the nuance of implementing it will look more verbose.

    Anyways, ideally the solution would be simple or added so it can be simple. These solutions are paths to work toward a solution without having to wait on the devs.

  • I can’t wrap my head around a solution to that. As is the impulse corrects the position but as the length is changing the velocities would have to be updated somehow.

    I tried gradually changing the length with a force but haven’t had much success.