R0J0hound's Forum Posts

  • You’ll have to calculate it manually since you can’t access mesh points, only set them.

    For simplicity I’m assuming the sprite isn’t rotated and the mesh points are just laid out in a square grid where you just changed the zelevation.

    First step would be to save the zelevations into an array as you set them.

    Start of layout
    — sprite: set mesh size to 10,10
    — array: set size to 10,10,1
    — For x from 0 to 9
    — For y from 0 to 9
    — — array: set at (x,y) to mountainFunction(x,y)
    — — sprite: set mesh point (x,y) to … zelevation= array.at(x,y)

    The next step would be to figure out what square a layout position is over. For simplicity I’ll use the mouse location and the sprite will have its origin at its top left.

    X0 = (mouse.x-sprite.x)/sprite.width*10

    Y0 = (mouse.y-sprite.y)/sprite.height*10

    Then int(x0), int(y0) would give the top left index of that square in the array. You may want to clamp that value or do a condition to see if the values are in the range of 0 to 10 otherwise it’s off the mesh. Btw 10 is just the mesh size.

    Anyways with that we are almost there to find the z. One approximate way is to bilinearly interpolate between the corners of the square.

    Z= lerp( lerp(array.at(int(x0),int(y0)), array.at(int(x0)+1,int(y0)), x0-int(x0)), lerp(array.at(int(x0),int(y0)+1), array.at(int(x0)+1,int(y0)+1), x0-int(x0)), y0-int(y0))

    A more perfect way is to understand that each square is made up of two triangles. You just figure out which triangle you’re over and use barycentric coordinates to interpolate the value over a triangle. I don’t know this over the top of my head but Wikipedia can help of you can derive it.

  • Maybe just add a hud layer that you don’t rotate? Again construct should do the conversions for you.

    Alternately if you just want to do the conversions your self here is the formula to rotate a position around a point. Maybe you can use that to unrotate the touch position or something.

    NewX=(x-centerX)*cos(a)-(y-centerY)*sin(a)+centerX

    NewY=(x-centerX)*sin(a)+(y-centerY)*cos(a)+centerY

  • In general construct will handle that for you. By default I think that touch.x will get the position on the top layer but you can specify the layer with touch.x(layer)

  • Vanilla Construct 2 doesn't come with any 3d. With some math you can transform sprites to move in a 3d way but for raycasting to make sense you'll want triangles. We can't draw arbitrary triangles or distort meshes like we can in C3. There is a trick though where we can make any triangle out of two right triangles. After that a raycast is just a 2d collision check with the triangle sprites.

    dropbox.com/scl/fi/g56pg4thhheg71yourl94/c2_simple3d_triangle_raycast.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's probably in how events work or something. I don't have a link.

  • It probably covers that elsewhere in the manual. By default all instances are picked. Conditions filter the instances that are picked, but some are just logical conditions and do no picking. When an object is created it becomes the only instance of that type that is picked for the rest of that event or until another instance is created.

    That's basically the meat of picking but there is also some nuance to "else", "or" and how created instances are added but you don't have to typically worry about those.

  • Another option to make it faster is to do the same thing in JavaScript. That would churn through the loops faster than the event sheet. Further down that rabbit trail is wasm but not sure it’s worth all the extra effort. Faster still could be to somehow leverage the gpu to do it in parallel. Maybe pack all the data into a texture, run that through a shader onto an output shader, and read back the pixels for the result. I may be mistaken though since I’ve never attempted that and your sim may not be able to be parallelized.

  • I think we are limited to being within the primary window with html5 and js. In theory it might be possible with nwjs or that new windows export since it could be extended to do stuff beyond browser stuff. But the main issue I see is you’d need to handle the rendering, input etc in those windows completely separate from construct since I can’t think of a way to have constructs renderer handle that. Overall I don’t think it’s feasible to do with construct without significant effort and time.

  • There’s a branch of math that deals with stuff like that called

    en.m.wikipedia.org/wiki/Mathematical_optimization

    But Wikipedia probably doesn’t have the most understandable examples. A simple example of that is maximizing the a fenced in area with the least amount of fence. Although I’m not certain it has any helpful tricks in your case since the triple loop is the one causing the calculation to take longer.

    Algorithmically you might be able to shorten the loops by sorting the lists of a,c and c by cost so you could use stop the loops when you know the rest of the instances were too expensive. Something like this:

    For each A ordered by cost
    - if A> income then stop loop 
    - for each B ordered by cost
    - - if A+B> income then stop loop
    - - for each C ordered by cost
    - - - if A+B+C>income then stop loop
    - - - look at priority…

    Since it is a simulation and if you’re happy with a good solution but not necessarily the best solution you could just compare three random instances of A,b,c multiple times. Could seem more realistic in a way since given the same problem humans would do that. Something like this:

    repeat 100 times
    Pick random A
    Pick random B
    Pick random C
    — do stuff

    Even that probably could be done better with a weighted random with a sorted list so that higher priority stuff is looked at more than low priority stuff. Or maybe sort the lists by cost and pick random instances by a normal random distribution (bell curve). That would make the stuff in the middle of the cost range be picked more than the the expensive or cheap stuff. To do that you’d need an array of the instances sorted by cost and a function to get a normally distributed random instead of the standard uniform one. I forget if c3 provides that.

    Array of A instances
    Sort array by cost
    i=int(normalRandom(array.width))

    Anyways just some ideas.

  • megatronx

    That’s how the pasting was made to work. It’s just drawn in place where the object overlaps the paster object. Hence the stamp icon.

    The quad draw function wasn’t meant to use an object’s effects, only its texture.

  • Over time the ball could lose some height with most all the behaviors.

    Here’s a way to not lose speed or height over time. The height will vary slightly but stay around the same.

    Var gravity=500
    Var vx=100
    Var vy=0
    
    Every tick
    — add gravity*dt/2 to vy
    — ball: set position to self.x+vx*dt, self.y+vy*dt
    — add gravity*dt/2 to vy
    
    Ball: collides with wall
    — set vx to -vx
    
    Ball: collides with ground
    — set vy to -600
  • What you showed was the non-interactive part which could be a fixed video, although I’ve seen that ad where it is interactive.

    It’s probably a mix of pre-baked videos of the fluid and actual fluid simulation in local areas, although it’s just a guess. Most fluid simulations are grid based or particle based or some mixture of the two. Or maybe they were clever and found a way to just reuse water animations and blend them together.

    This channel shows two ways that fluid simulations can be done in general (it’s not construct related).

    m.youtube.com/watch

    m.youtube.com/watch

    You poke around the forum for construct related examples. The simplest would be to using a lot of small physics balls to do the simulation. It doesn’t scale well though. Another is just simulating the surface.

    Overall the event system is a bit heavy to implement a water sim. The physics behavior is a bit better but it doesn’t behave the same and also is a bit heavy with that many objects. JavaScript would be the fastest way to go, or maybe using an existing library. It’s just the matter of getting it to play nice with constructs engine.

    The main issue getting some custom library to render in construct. You need to modify how the library renders so it just uses constructs renderer which may or may not have all the features you need. Another approach is trying to modify constructs renderer instead, but it’s not designed to allow that easily and officially it’s discouraged and not supported. A third way is to just have a separate canvas with its own renderer and you’d layer the canvas’ on top of each other.

    Anyways. Just some general ideas. Personally I’d try to somehow fake it as much as possible.

  • megatronx

    Sorry, I'd avoiding any aspect of making plugins and I'm not a fan of debugging ai generated stuff.

    megamente Br

    Alexander Wiseman

    I haven't used this plugin in months but I tried it and it works here. You'd load the texture to a tag, say "tex" then set the object's texture to that tag. As long as your mesh uv's are good then it should show the texture.

  • Well what’s causing it will be hard to spot. The waits make it hard to know the exact order things are run. Maybe don’t let the function run until the previous one completes. After all the order you want things to run is fixed. You could also try the timeline or just make it in one function so it’s easier to follow the logic.

  • So as you have it now the “every 0.01 seconds” it would trigger ~100 times a second on a 240fps screen, and 60 times a second on a 60fps screen ( since anything lower than dt is dt with every x seconds.

    If you want it to update at the same fixed rate you could remove the every 0.01 seconds and do something like this.

    Var t=0
    
    Every tick
    — set t to t%1
    — add 100*dt to t
    
    Repeat int(t) times
    — do stuff

    Or did you want it to be continuous instead of doing the steps you were using?

    For that, remove the every 0.01 seconds and change the set x’s from:

    Set x to self.x+rate

    to

    Set x to self.x+rate*100*dt