R0J0hound's Forum Posts

  • The example just did a grid mesh of points and edges since that’s fairly simple to do, results in a nice uniform simulation and finally because it matches what c3 can do with its distort mesh, which also is a uniform grid.

    You could conceivably put points anywhere you wanted and have edges all over. The issue is it’s tedious to setup. Also it wouldn’t be simple to make work with the distort mesh.

    Just thinking aloud though.

    Where there’s a use case and an interest to do it there’s a way. What you want to do is still vague.

  • You’re welcome

  • As for the math part, sin and cos in construct take degrees and not radians like in that example.

    So just multiply the values inside the sin and cos by 180/pi and it should be correct. No idea if it’s the same noise function though.

  • Here's the example using an array.

    dropbox.com/s/1hevbeddf81x3u6/grid_motion_array.capx

    The array has 1 if something is at that grid space and 0 if nothing is there. That's initially setup at the start of layout.

    motion logic is basically this:

    want to move right?
    is right grid position empty?
    -- set current grid position to empty
    -- set right grid position to full
    -- start move

    You then look at the sprites in order as you have with "for each ordered".

  • I probably explained it poorly. The gist is to not check the objects current position for collisions, but the position it’s moving to.

  • On further thought you can avoid the array entirely. You just need another sprite for each moving sprite to be for collision detection. The idea is that additional sprite is where the moving sprite will be going and can be used for collision detection.

    Here's a c2 example that can load into c3. The tilemovement behavior isn't in c2 so i did it with events.

    dropbox.com/s/mnci1fyhtbimjlm/grid_motion.capx

  • One solution is to remove the solid behavior completely and do your collision detection yourself. An array can be useful for this since its grid based. Then you fill the array with wherever the objects are. The trick is when you move an object to update its position in the array to the goal position so it’s old position is free for other objects to move onto.

    The setup of the array could look like this:

    Start of layout:

    — Array: set size to (layoutWidth/32, layoutHeight/32, 1)

    ——array: for each xy

    —— compare tile at(array.curx,array.cury)=-1

    ———array: set (array.curx,array.cury) to 1

    —— for each fmotion

    ———array: set (fmotion.x/32,fmotion.y/32) to 1

    Then before simulating moving left for instance, you’d check if that spot was free, and if it was simulate the key press and update the array.

    Array at (fmotion.x/32-1, fmotion.y/32) =0

    — fmotion: simulate left pressed

    — array: set (fmotion.x/32, fmotion.y/32) to 0

    — array: set (fmotion.x/32-1, fmotion.y/32) to 1

    It would be very similar for the other three directions. You’d use that with the for each ordered logic you already have.

    That’s at least one idea. There may be clever ways to make it simpler. The issue with the solid behavior is it doesn’t know how to handle moving objects.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Test 4:

    Circuit simulator via "Node Voltage method"

    dropbox.com/s/qfnx3hsg1imuoks/mesh_circuit.capx

    An offshoot of some recent forum topics. It allows you to build a circuit out of batteries, resistors and wires. Then it figures out the voltages of each node and visualizes the current flow.

    Controls:

    * left click drag nodes, resistors and batteries.

    * right drag to make wires between nodes, or right drag from empty space to cut.

    * batteries and resistors can be dropped onto wires.

    * right click on batteries to reverse them.

    * double click to destroy node, or create new one.

  • I’m going to have to pass on this one and defer to other users that use c3 and are familiar with how to use the mesh distort feature.

    I’m avoiding using c3 so I’m not really much help here.

  • You probable should do "set mesh" at the start of the layout or something. It may keep resetting things there. besides, it would be set to the width and height of the array.

    And what are those two additional -1's in "set mesh point"? If they are uv's they could take i/(array.width-1) and j/(array.height-1) as values. If they are something else ignore that.

  • Well in the verlet_cloth_paster.capx the distortion is drawn in events 15-17. Those are the only parts dependent on the paster plugin. Remove the paster plugin and the capx should be openable in c3 since only vanilla features are used then.

    I don't use c3 so I won't be making a cp3 example, but as i understand it you can make it work with distortion mesh with one action added to event 16. Somewhere you'll also want to set the x and y divisions of the mesh distort to cloth.resx and cloth.resy.

    for each cloth
    array: for each xy element
    -- set i to array.curx
    -- set j to array.cury
    -- cloth: set distortion point (i,j) to (p(Array.At(i,j)).x, p(Array.At(i,j)).y)
  • Hi,

    What are the issues you’re encountering?

  • Looked around the web for a bit on how electronic simulators typically work. Seems the basis of it is Ohm's law (I=V/R) or in more useful terms: Current=(voltageOut-voltageIn)/resistance. That can be used to see how voltage changes when moving through a component.

    For a simple ring of components with one battery, you should be able to just start with the positive on the battery and loop around till the negative is reached. Just use ohm's law at each component, and if negative can't be reached then stop since there is no complete circuit.

    The general case with branches is a bit more interesting. Found this topic on it that seems to give a good starting point. Looks like it's done by solving a system of linear equations. To do this in construct we could store the system in an array, and implement an algo to solve it.

    electronics.stackexchange.com/questions/91416/how-do-circuit-simulators-actually-work

    I can see it working if everything is connected in loops. Not sure if it handles dead ends and loops without batteries. Might have to do some pruning beforehand.

    Anyways, seems to be a rabbit hole for sure when making a circuit simulator.

  • Well the bulk of it is a vector projection, so reading a tutorial on vector math may be useful.

    This equation sets t to a normalized vector projection of p onto the line between the two centers.

    t = clamp(((p.x-c0.x)*(c1.x-c0.x)+(p.y-c0.y)*(c1.y-c0.y))/((c1.x-c0.x)^2+(c1.y-c0.y)^2),0,1)

    Combined with:

    targetx = lerp(c0.X,c1.X,t)

    targety = lerp(c0.y,c1.y,t)

    you end up with the point closest to object p on the line segment between c0 and c1.

    If you could do vector math directly in construct it could look like this:

    A = p-c0 // vector from c0 to p
    B = c1-c0 // vector from c0 to c1
    t = (A dot B)/length(B)^2 // normalized vector probjection
    t = clamp(t, 0, 1) // limit to the line segment
    closetPoint = c0 + B*t // get point by lerping between c0 and c1 by t

    So anyways, you get a point between c0 and c1 close to p.

    Next it moves p toward that point so it's exactly a 'radius' away.

    Then it turns p left 90 degrees and moves forward at "speed" pixels per second.

    Honestly it's just a bunch of simple things put together. I usually draw a picture as i go coming up with these things. Then i simplify the math as much as possible.

    You could google things like "vector projection" and "point closest to a line segment" to find more info about the math.

    The construct specific stuff:

    clamp(value, low, high) limits a value to be between a low and high value

    lerp(a, b, t) moves a percentage from a to b by t. Where t is between 0 and 1.

  • One idea is to find the closest point on the line segment between the two centers from the car. Then move a radius distance from that point.

    Here's it in one event. Change the radius and speed instance variables as needed. The long formula is just a vector projection in case you were curious where it came from.

    dropbox.com/s/eeuayajvv2lv2l4/orbit_line.capx

    The only issue is the speed around the curve will be different than on the straightaways, but it's not really noticeable.

    A different solution i've tried in the past is to divide up the sections of track into straight and curved sections and moving along them.

    construct.net/en/forum/construct-3/how-do-i-8/keep-object-train-curve-rail-143038

    It didn't consider differing radiuses but the speed is constant even on the curves.