R0J0hound's Forum Posts

  • So, creating the mesh is something you’d probably do just once. Like:

    Start of layout

    — vertex (100,0,0)

    — vertex (100,100,0)

    — vertex (0,0,0)

    — save as mesh “triangle”

    Now it looks like you have a bunch of imagepoints that make up the polygon border of the image. You need to convert that to triangles. One simple way to do that is to do a triangle fan.

    Something like this. P is the imagepoint you want to start the fan from, best if you use a concave point. Ipx and ipy is sprite.imagepointX/y, and count is sprite.imagepointCount. I just didn’t want to type that all out.

    Var p=1
    Var i=0
    Start of layout
    — repeat count-2 times
    — — set i to p
    — — vertex(ipx(i), ipy(i), 0)
    — — set i to (loopindex+p)%count+1
    — — vertex(ipx(i), ipy(i), 0)
    — — set i to (loopindex+p+1)%count+1
    — — vertex(ipx(i), ipy(i), 0)
    — save as mesh “triFan”

    Notice it matters what imagepoint you start with. See below. Also this won’t work for all shapes, but hopefully will. For any shape that doesn’t work with a triangle fan, you’d need full blown triangulation of polygons.

    Also I guess I didn’t specify uvs. For any imagepoint you can convert it to uvs with

    U=(Sprite.imagepointX(i)-sprite.bboxLeft)/sprite.width.

    V will be similar but with y, top and height.

  • There isn’t a distance limit so you just have to play with the numbers.

    Basically it’s a mix between the acceleration and spring stiffness. When the spring is stretched far enough it will counteract the acceleration.

    The damping makes it less springy. Set it to 0 to see it bounce all over. The damping slows it down.

    320 and 240 were just half the 640,480 window.

    I used the layout size to limit the position we use to the scroll area. It’s not needed if you had unbounded scrolling.

    The a and d variable are just the angle and distance from the camera to the mouse.

    There’s always some feature I forget about with my examples. You may still be about to use screen shake after you set the mouse position. Or we could do our own with some random values added to the scroll position.

  • CustomMovement is unwieldy, I never use it.

    Here's what I came up with:

    uc28e693f766bf5e2ddf38d380a6.dl.dropboxusercontent.com/cd/0/get/Ch8-T02aEJyAzQn74kIvy-wDSb0RedhOCGClH1axrMgxrt4WEc12t6vGSeG2qJqdhieZBuAqCC5p6nFXND5Gh31h56mcBxtnL3sTn0Fu9LbBhgkRAUj-HmP_gDVRpARoHHfSrwA-nRH8kvyWdGfEWQOk/file

    or radial instead

    ucfe657ef0730f61b9a5ece746cd.dl.dropboxusercontent.com/cd/0/get/Ch_XTCSEhokxRSj_SlrcujhBnrqSm3gqBilAkP77jGHvr0zkiw3Tac1WZUxrk-6-8la20jmSwjw2uB289nwxBpY0QEQFN4jKWrsMn4s30ZbtWAqAcD01-cB4r72Aechkw_cGuDrlx92onGFR0WKbUlIU/file

    Basically the camera is controlled by a damped spring which gives nice easing in and out. There are three variables you can tune:

    acceleration controls how fast it moves.

    stiffness controls how far you can look and how fast it returns to the center.

    damping gets rid of bouncing. higher values also make everything more sluggish. too low and there will be overshoot.

    Edit:

    Here the spring is applied to the whole camera instead of just the look around:

    uc3fa2ea77441290562065074715.dl.dropboxusercontent.com/cd/0/get/Ch_WcxhMvNEvefAdeGJiUy4hmQcaRssZo5K0EONGB1YhQMH592naiXM-hjv_DekRoM1jbO76nBe4HZSdSwHKroaRq1IQf2cWc9nfUOBbCqyjRXFD5JuLoTkr1dSbjbzb-Pn-_9XS2yUUZuTRXzxIegTH/file

    Kind of gives the impression of a real camera operator.

    Edit2:

    uc24788ec6ed8e453a318d48783e.dl.dropboxusercontent.com/cd/0/get/Ch_6OPGOWrZ2xN72T7lSLjlpCWzhbYRnEsSp2sgl7S0AmL9q8F_r0hEDASUlhJgyN3obA7po5prePsV3XAE6CF011nT2mfJmOHnJrRqUggRfa-YIdj21QMpjEj3R2L0i-pbMuuLnAg7MIjtSmk11nFER/file

    Fix to ease down when scrolling to the edge of the layout.

  • Probably the solution is to not use lerp. Instead move the scroll around by applying an acceleration which would eliminate the jarring. The idea is you’d want an ease in and out instead of the jarring ease out that typical uses of lerp provides.

    I don’t have the time today to make a complete example but the basic logic would be:

    Mouse is in edge region? Accelerate camera to a max distance

    Else decelerate back to 0.

    Anyways there’s more to it than that. The acceleration provides the smooth motion and you can utilize a formula so you can gradually stop at a specific location.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That’s the only fancy thing you can do with expressions.

    From most complex

    TypeName(index).behavior.method(param1,param2)

    To most simple:

    TypeName.property

  • One way that’s pretty simple is to give your sprite an instance variable “target” and place the waypoints on the layout in the order you want to follow. You could alternately place the waypoints in any order and use an instance variable to set the order.

    Anyways the events would look like this:

    Every tick
    — sprite: move forward 100*dt pixels
    
    Sprite: on collision with waypoint
    — sprite: set target to waypoint.iid+1
    
    Pick waypoint instance sprite.target
    — sprite rotate 60*dt degrees toward (waypoint.x, waypoint.y)

    The 100 is the speed, and 60 is how fast it turns.

  • Is the gltf file you’re using one of the ones included in examples for this plugin?

    I helped with the initial gltf loader part of the plugin. The plugin should be able to load any gltf file saved as embedded from blender, or any other program.

    With the gltf format it has three different variations:

    Gltf + bin

    Gltf embedded

    Glb (binary)

    The loader in this plugin only handles the embedded variation. Which seems like the format you’re using since it works with the Babylon test bed.

    Anyways if you’re able to share the gltf file or a c3p project with the file it may help to find the issue.

    From the error it looks like something isn’t loading correctly.

    Mikal

    It may be something as simple as the the exporter that made the gltf file not adding all the properties that the plugins loader expects. I thought it follows the spec but this may be a case where if that part isn’t there you’d just add it from the other info in the file.

  • int works the same as floor. They both round down, so your probability will be equal for all dice rolls with int(random(1,11)).

    Unless they changed the behavior of int to just truncate the float to an int. But you would only see that with negative numbers.

    int(0.5) = 0

    round(0.5) = 1

    floor(0.5) = 0

    ceil(0.5) = 1

  • Ultimately you can store the data any way you want. In this example I just stored it in a list of number,name;...

    Mainly because it was simple to parse.

    uc5ff84e46bbd754646108bf6012.dl.dropboxusercontent.com/cd/0/get/Ch8oP9p0pQNB3fq9PHr_PHh8G60kt_JsxT-VZeYa3iZSieiI27GeQi_SnaYvVjwzEpLuswJrGgwXmI5R09zTisDShnixiQXmcY13ogFJ1x5TMQD3Hg67Xs-P1f2vyYB2JNQAskVxZuf0a1ifkMhkD7nK/file

  • If you put all those values in an array and just get one at random that would work.

    Array.at(int(random(Array.width)))

    For a more deluxe and compact version you could store the values and weights of each value. The sum of all the weights should be 1.

    Then to randomly pick a value based on the weights you’d:

    1. Generate a random value 0-1

    2. Loop over the array

    3. If the current weight<value? Then subtract the weight from the value and look at the next array position.

    4. If weight>=value then you’re done and the array position you’re on is the value to use.

    Anyways that’s the gist of it at least.

  • Is it all the odd numbers from 1 to 100?

    int(random(50))*2+1

    Or is it a different set of odd numbers?

  • Can’t open the project, but filtering can be done by looping over each entry in the array, checking its length and removing it if needed. The only catch is you’ll want to loop over it in reverse.

    Array: for each x
    Compare: len(array.at(array.width-1-array.curx) >3
    — array: remove at array.width-1-array.curx
  • Skimming over it it doesn’t look like there’s anything preventing it from being ported over.

    The vertex shader portion doesn’t do anything, which is good since construct doesn’t let you modify that anyways.

    The fragment shader has a bunch of uniforms: floats and vec2s which can be two floats.

    The rest would depend on if GLSL is the same for webgl and OpenGL. So there may be a need for some fiddling.

  • That’s kinda what I meant with calculating. You’d effectively be just doing all the math that mouse.x/y does behind the scene. Which would work but I don’t think it provides much benefit.

    As for the lagging of the sprite behind the actual mouse cursor. I thought that was just because of latency between code and the drawn frames or 1/60th of a second.

    An alternative is the to set the mouse cursor from a sprite, which doesn’t lag behind but it’s on top of everything as it’s not truly a sprite then. That reason that doesn’t lag is the operating system is drawing it then which is more input event based instead of frame based.

    Anyways unless the lag you’re seeing is something different. In which case I’m all for tightening it up if possible.

    Edit:

    It just occurred to me that when you scroll some stuff doesn’t get recalculated till the end of the tick. For example viewportLeft(). It possibly could be the same for the mouse(layer).x expression. That could be lag you’re getting which is different than the other one I mentioned.

    You’ll have to test it but assuming that that setting the scroll position causes mouse.x to update till the next tick you can order your events like this.

    Basically before scrolling, save the scroll position to variables. Then after the scroll correct the position.

    Set sprite x to mouse.x

    Set oldScrollx to scrollx

    Set scroll position

    Set sprite x to self.x-oldScrollx+scrollx

  • Best I can tell construct only provides the viewport* expressions to find the width of the view in layout coordinates.

    The browser object, in the c2 docs at least, mention screenWidth and screenHeight as values too.

    With js you can also get the width/height of the html canvas if you really want to handle it from scratch.

    There’s also the system expressions layertocanvasx/y and canvastolayerx/y expressions that may be useful.

    Does it only happen in full screen?

    Honestly for positioning things don’t use absolutex/y. You can use it to see if the mouse moved.

    Otherwise as an exercise in math you can map the absolute mouse position to the layout position in a correct way.

    ///////////

    Intuitively you should be able to put your cursor sprite on any layer and position the sprite with

    Set position to mouse(self.layer).x, mouse(self.layer).y

    And it’ll just work, full screen or not. If it doesn’t then it’s a bug I say.

    You can still utilize absolutex/y to check if there was mouse motion. Like

    Global number oldx = 0
    Global number oldy = 0
    
    Compare oldx <> mouse.absolutex
    Compare oldy <> mouse.absolutey
    — do something because the mouse moved
    
    Every tick
    — set oldx to mouse.absolutex
    — set oldy to mouse.absolutey