R0J0hound's Forum Posts

  • You do not have permission to view this post

  • There isn’t a best way. There are many different ways like I roughly listed in the previous post, each with pros and cons. But realistically you’d just pick one.

    Create a sprite and call it node. Give it two instance variables: path and index. You’d then place instances of node on the layout in the shape of the path you want. Next you’d set the instance variable values. You’d set index to 1 for the first node, 2 for the second, and so on. You’d then set path to the same value 1 for all of them. You can create more paths later by just having different values of path.

    Next you need something to follow the path. Create a sprite and call it mover. Give it two instance variables: path and target. Also give it the bullet behavior.

    In events you’d then do something like

    Start of layout 
    — mover: destroy
    
    On click
    Node: path=1
    Node: index=1
    Repeat 10 times
    — create mover at (node.x-loopindex*32, node.y)
    — mover: set path to 1
    — mover: set target to 1
    
    For each mover
    Node: path=mover.path
    Node: index= mover.target
    — mover: rotate 100*dt degrees toward (node.x,node.y)
    
    Mover: on collision with node
    Node: path=mover.path
    Node: index= mover.target
    — mover: add 1 to target

    You can change the rotation speed by changing 100*dt. You probably want to change the bullet speed too. Too fast with too slow of turning will prevent it from being able to reach the next node, but that’s easy to tweak. You can change the amount and spacing of the movers in the event that creates them. You probably want to delete the movers once they reach the end of the path somehow.

    As an exercise you could also stretch a sprite between consecutive movers to avoid visual gaps.

    Edit:

    Third party plugins are useful, but users seem to avoid them because they don’t like that the people that made them don’t usually stick around till the end of time to fix possible issues that come up from browser or construct change. You’re already using c2 that could possibly break from a browser change although that’s not very common. As to if third party plugins make it harder to port? That’s a question for those who do the porting.

  • I’m already unfamiliar with the game and the formula. But I’m assuming the formula is mostly correct.

    I’d want to verify this, but assuming it’s correct this should give to probability that exactly k of the unknown n dice are the same value.

    Prob(n,k) = fact(n)/(fact(k)*fact(n-k))*((1/3)^k)*((2/3)^(n-k))

    That’s with wilds. Without wilds 1/6 and 5/6 sounds reasonable.

    Normally for the ai to decide to say Liar or not it looks at the probability that there are at least k dice with the same value.

    So for example if there are four unknown dice.

    The probability of at least 2 being the same would be:

    Prob(4,2)+prob(4,3)+prob(4,4)

    And the probability of exactly two being the same would be

    Prob(4,2)

    The formula with the summarization I gave before would find at most or

    Prob(4,2)+prob(4,1)

    Which doesn’t seem right.

  • You shouldn’t need to be working with CssPx at all. The bounding box/quad is already in layout coordinates and the renderer takes layout coordinates as parameters. Also layout coordinates don’t change when the widow/scroll or the layout size changes.

    So for example in the draw() function of your plugin you could do something like this to draw a triangle centered on the object.

    const x=inst.x, y=inst.y;

    Renderer.convexPoly([x,y-50, x+50,y+50, x-50,y+50]);

    The bounding box would be based on the objects size and center so ideally you’d change the object size so that the bounding box would be tight fitting around the points of the polygon.

  • You probably should stop posting your question in both the c2 and c3 sections since you’re only after c2 solutions.

    C3 has the timeline editor which probably makes it easy to move things alone a path with minimal events. C3 also has the distort mesh where you can distort a sprite in a curved shape if you wanted.

    In c2 you have to come up with a way to define a path and move along it manually. Theres even some third party plugins to move along a curved path pretty easily.

    A cheap way to move along a path is to use the pathfinding behavior to move from point a to b through multiple waypoints to make the loop.

    You could also use the bullet behavior with a bunch of sprites places to make the curve. You’d have it target the first point by rotating the sprite toward it then when it collides start targeting the next and so on.

    Theres also some more rigorous mathy ways to go about it.

    To give it that curved line look you can just launch a bunch of sprites to move along the path and stretch sprites between consecutive sprites. There are also drawing plugins that possibly could be used for different looks. Or if you space the sprites close enough you may not need to stretch sprites.

    Basically looks like you’d define multiple paths. Then you’d pick one and spawn a bunch of objects to move along it at different offsets. Then you’d use stretched sprites or something to give it a continuous line look.

    Generating the paths on the fly could be possible too. But it doesn’t seem like something that video covers.

    Anyways, just some ideas.

  • That’s caused by the drawing order of images with transparency. Ideally polygons are drawn back to front, and construct generally tries to do that. The issue is just sorting the polygons won’t always work. I guess intersecting polygons is a common case that can’t be solved by sorting.

    One possible solution is to use a discard shader on problem sprites. What it does is not draw the transparent parts so stuff behind it is shown even if the order isn’t ideal. The only con is it would be a hard jump from transparent to not which may or may not look good in your project. Someone made one, but I don’t recall where. I think someone also made a dithered semi transparency effect too. Makes me wonder if you could render at double resolution and smooth resize it down to half resolution to get rid of dithering and hard edges.

    Another idea is to somehow control the sorting yourself to see if you can improve things. Fiddle with zorder and zelevation perhaps? In previous tests it wasn’t straightforward to override it. For example getting the walls to be drawn before the transparent stuff would help with the first artifact. For the second drawing the sword after the character would kind of help but I imagine the sword would get the clipping then.

    With the exception of intersecting polygons and cases where there’s a cyclic loop (ex: A in front of B, B in front of C, C in front of A) then doing a topological sort instead of a distance sort can help. But it’s probably not worth the effort here.

    Another idea is to split the objects into smaller ones. Or maybe dynamically split the intersecting polygons. An algorithm like BSP does that and likely would solve it. But again probably not worth the effort here and it would be rather heavy.

    Leveraging the gpu to solve it per pixel is another idea. Intuitively each pixel would be a list of colors and zdepths which would then be sorted. One algorithm called depth peeling supposedly does that semi efficiently. But that sort of thing is lower level than what’s really possible with construct’s renderer.

  • Well, what does construct provide to be able to do this? Maybe:

    System: pick 3dshape overlapping point (mouse.x, mouse.y)

    If the bottom of the 3dshape is on the z=0 plane then that will let you click on the bottom face. The other faces though? you're out of luck with Construct features. You'll have to do something from scratch...

    First you'll need the mouse ray. You can get that from the camera distance to the screen. One way to calculate that is from a non scrolling 2d layer: xyz: (mouse("2d").x-320, 240-mouse("2d").y, 240/tan(fov/2)). 320,240 is half the viewport size. Next you'll have to normalize that vector and rotate it by the inverse of the 3d camera orientation. That will give you a ray direction from the camera position.

    The second part is to do some kind of raycasting to see if and where the ray hits a 3d shape. Using an sdf with raymarching is a relatively simple solution for a single unrotated cube.

    dropbox.com/scl/fi/on24os5ezt8bqkugnea58/raycast_mouse_cube.c3p

    Overall for this kind of problem you figure out how to solve it from scratch and then adapt it to what features construct provides.

  • Roughly you’d calculate the angle difference between the two edges, and if the angle difference exceeds the angle limits you specified then you’d rotate the end edge till the angle is within range.

    We can calculate the angle of the edges with the angle() expression. To get the angle difference we could use anglediff() but we need the signed angle diff where its negative when CCW. That can be calculated with angle(0,0,cos(a-b),sin(a-b)). Then you’d check if the angle diff is greater or less that an angle limit. And if it is rotate the endpoint so it’s back in range. The formula to do that is:

    Pos: ((x-cx)*cos(a)-(y-cy)*sin(a)+cx, (x-cx)*sin(a)+(y-cy)*cos(a)+cy)

    As an example (barring any typos) this will move multiple instances of a sprite in a chain. The first instance will be moved to the mouse position, then all the following instances will be moved to be 32 pixels from each other. Then from the third instance on it limits the angle to the range (-10,10)

    Var p0=0
    Var p1=0
    Var p2=0
    Var da=0
    
    For each sprite
    — set p2 to p1
    — set p1 to p0
    — set p0 to sprite.iid
    — compare: loopindex=0
    — — sprite: set position to (mouse.x,mouse.y)
    — compare: loopindex >0
    — — sprite: move distance(self.x,self.y,sprite(p1).x,sprite(p1).y)-32 pixels at angle angle(self.x,self.y,sprite(p1).x,sprite(p1).y)
    — compare: loopindex>1
    — — set da to angle(sprite(p1).x,sprite(p1).y,sprite(p0).x,sprite(p0).y)-angle(sprite(p2).x,sprite(p2).y,sprite(p1).x,sprite(p1).y)
    — — set da to angle(0,0,cos(da),sin(da))
    — — set da to da>10?(10-da):(da<-10?(-da-10):0)
    — sprite: set position to (self.x-sprite(p1).x)*cos(da)-(self.y-sprite(p1).y)*sin(da)+sprite(p1).x, self.x-sprite(p1).x)*sin(da)+(self.y-sprite(p1).y)*cos(da)+sprite(p1).y)
  • Well the imagUrl is just a string which you can download with the browser object’s action: invoke download.

    With nwjs you can save it to a file too.

  • In events “sprite.something” only gives numbers and text.

    The drawing canvas is probably what you need to use to access image stuff. You’d paste the sprite to the canvas then you can access and set individual pixels or get an imageurl to save or download a png/jpg file.

  • Found if you set sampling to nearest then the thin slivers go away with meshes. It's probably not a viable solution since you'd want smoother sampling for everything else but still could be useful.

  • Likely int() uses parseInt() under the hood so it would still return 0. The string would need to start with a number for int() to work.

    If your layout makes have the pattern of a letter then a number then you could do int(mid(layoutname,1,10)) or something.

  • Mesh is almost an option if we can avoid the thin transparent gaps. I want to investigate fiddling with the math to see if I can remove or reduce the rounding errors. In theory I could scale tue triangles up slightly to eliminate it too. If that works out then I’ll make it combine triangles to reduce object count. Anyways, I’ll let you know. As is it’s mostly trivial to change between drawing with canvas or a mesh.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's the wip of the triangulation. It works with the the polygon defined by sprite instances in a CW order.

    Using a mesh to display the triangles didn't quite pan out because it gives thin transparent slivers due to math rounding. So it also lets you draw the triangles with the canvas as well since it doesn't have the slivers. It doesn't look worthwhile to extend it to generate convex polygons or triangle strips at this point. It will need reworking if you want to define the polygon in another way other than sprite instances. Doesn't work with self intersecting or CCW polygons, but the CCW case can be solved by detecting the order and reversing the list.

    dropbox.com/scl/fi/png6jg6a1qresctjq5ra6/triangulate_ear_clip_mesh_wip.c3p

    Alternately, if you want to use js for this you could look into this one:

    github.com/mapbox/earcut

    Or you could take the triangulation function out the old c2 chipmunk plugin. That one generates convex polygons.

    Edit:

    Just noticed that points ordered in CCW order could be used for a convex hull.

  • If the orbit is controlled by physics then to make it be able to orbit slower you need to reduce the gravity force. Or maybe just don’t give physics to the moon and move it with the orbit behavior instead.