R0J0hound's Forum Posts

  • I was able to test mine as working so I now see what you had amiss.

    You had:

    (Vx / 10)* (Vy + sqrt(((Vy * Vy) + (2 * 10 * Y0Height)))) - X0

    But it needs to be this. 500 instead of 10, and you don't subtract x0.

    (Vx / 500)* (Vy + sqrt(((Vy * Vy) + (2 * 500 * Y0Height))))

    That will the calculated be approximately the actual. It will be off since the floor is hit a bit early.

  • You could delay it a frame with something like this pseudocode. Beyond that I guess you'd have to implement the platform behavior from scratch so you can actually know when a collision occurs.

    bool overlap = false;
    bool futureOverlap = false
    
    onTick(){
     if futureOverlap==true && overlap==false
     then doStuff()
     
     overlap = futureOverlap
     futureOverlap = obj.isOverlappingSolidAtOffset(obj.vx*dt, obj.vy*dt)
    }
  • One way to do an undo is to make a save of the game state before you move. It's the same kind of problem as saving your game, you probably can utilize construct's save features for that. Another way is to just save the changes of each move. Could be a bit trickier though.

    Hints would be done in the same way as a real player finds a move. Basically come up with a way to check all possible moves.

  • Messed with your example briefly but no luck. Do note, that the gravity value you should use in the equations needs to be 50x the gravity value that the physics behavior uses.

    Anyways you could try it with the bullet behavior instead in case the physics behavior is throwing it off.

    I mean your logic seems sound. There’s probably something I didn’t notice that’s throwing it off. If it helps this is what I come up with when working out the math. I haven’t tested it though.

    Var g=500
    Var x0=0
    Var rangeCalc=0
    Var rangeActual=0
    
    Start of layout 
    — ball: set position to (0, 400)
    — ball: set velocity to (100,-100)
    — set x0 to ball.x
    — set rangeCalc to (-vy + sqrt(vy*vy + 2*g*(480-ball.y)))*vx/g
    
    On ball collides with ground
    — set rangeActual to ball.x-x0
  • I guess the use of the trig functions look obscure. If it helps this is the formula I’m using that uses trig. All it does is rotate an xy point around 0,0 by some angle.

    NewX =x*cos(a)-y*sin(a)

    NewY =x*sin(a)+y*cos(a)

    The cool thing about it is you can rotate other ways too such as xz, just replace the y with z in the formulas.

    This is all I’m using that equation for:

    // make a circle

    Vector(radius1, 0, 0)

    RotateXY(b)

    //Then rotate the circle in an arc to make the rings.

    Move(-radius1, 0, 0)

    RotateXZ(a)

    The equation I used is just all that combined and simplified. All the equations I ever use in my examples are like that, a combination of simple steps combined and simplified.

  • You can do a lot with mesh distorts. Here's a way to generate an arch mesh. There's just no end faces although those could be added.

    dropbox.com/scl/fi/5a23jevq10r3kqzapd7a9/arch_3dmesh.c3p

    In a similar fashion it's possible to take any polyline and revolve it around an axis, or extrude it along a path to make a 3d shape from one distort mesh. So spheres, cylinders, cones, torii, screws, ... etc, could be made. Actually with some creativity you can make all kinds of 3d shapes with distort meshes.

  • Probably check the browser's console to see if there are any errors. If that's good you could do some smaller tests with the array scripting api to see what works and what is not doing what you expect.

  • To be able to load a json string into the array object it needs to be in a specific format. You can see that format with array.asJSON.

    Something like this should work in converting your json string into a 1d construct array json.

    function convert(in){
     in = JSON.parse(in);
     let out = {c2array:true,size:[0,1,1],data:[]};
     for(let i=0; i<in.length; i++){
     out.data.push([[in[i].x]], [[in[i].y]]);
     out.size[0]+=2;
     }
     return JSON.stringify(out);
    }

    Then after loading that into the array object you can access the xy of the nth point with:

    X=array.at(n*2)

    Y=array.at(n*2+1)

  • This would set obj2 from obj1:

    Obj2: set y to lerp(1250,410, unlerp(310,-1800,obj1.y))

    And this would set obj1 from obj2:

    Obj1: set y to lerp(310,-1800, unlerp(1250,410,obj2.y))

    You’d only use one of those at a time. Say when you’re moving one you’d update the other.

  • This question comes up a lot.

    For plotting the path and dealing with the wonky units the physics behavior uses.

    construct.net/en/forum/construct-3/how-do-i-8/create-physics-trajectory-178459

    And similarly to pick an initial velocity so that the projectile hits a certain location.

    construct.net/en/forum/construct-3/how-do-i-8/solved-physics-object-impulse-179677

    1. You basically got the gist of it.

    The physics behavior by default has a fixed timestep of 1/60. But it shouldn’t matter if you update vy like so.

    Vy = vy+ay/2*dt

    Y = y+vy*dt

    Vy = vy+ay/2*dt

    As you found for a physics behavior gravity of 10 the actual vertical acceleration will be x50 times bigger or 500. 50 comes up a lot in the units of the physics behavior.

    2. The second link covers a way to calculate initial velocities.

    3. X(t)=x0+vx*t

    Y(t)=y0+vy*t+0.5*ay*t*t

    4. Impulse isn’t a force. Basically J=mass*velocity so it’s used to change the velocity in an instant. It’s cleaner to just set the velocity than calculate the impulse. But if you really want to calculate an impulse that changes the velocity you can do this:

    Jx = vx*mass/50/50

    Same for jy

    The mass expression provided by the behavior just gives the density is not correct. The correct formula is:

    Mass = area*density/50

    But maybe there’s some conversion you can do.

    Beyond that you can account for linear damping too, and there may be other subtleties.

  • Mousedown triggers when a button is first clicked. Even if you clicked both buttons at the same time mousedown would be called for each button individually. You can’t directly query the state of a button with the browser so a solution is to just update some variables from mousedown and mouseup events, and then you can look at those variables to access the current button state.

  • You can look at the obj file in a text editor to see if it looks correct. The lines starting with v are the vertices and there is only 8 of them if it’s a cube.

    Other than that I can’t really help. The obj file format is simple and having it load with the wrong offset and size isn’t really the kind of mistake that would happen in the loader.

    So I guess just try to fix the cube in that 3d program, and maybe check the meshes you’re using for the ground or other objects you’re trying to align with.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Three changes and it will work.

    1. Make the gravity local variable static. Since it’s in a group it’s just a local and gets reset to 0 every tick as is.

    2. Make the gravity variable x50 times what you use for the physics behavior gravity. Why? With box2d the standard use is to scale the physics units from the pixel units. That shouldn’t affect us but when they made the behavior they didn’t make sure the units were all uniformly converted. So x50 comes up a lot.

    3. Use (vx,-vy) when you set the velocity. A negative was forgotten when solving the formula.

    And as a bonus:

    4. Use (vx,-vy-gravity/60/2) when you set the velocity. Without that the path will be slightly lower than the target. Why? There is something off when things update in the behavior. It applies gravity once. However I think this mainly happens when objects with physics are just created. I honestly forget, but in the chipmunk behavior I made a point to avoid that quirk.

    Cheers

  • That example should have what you need. I mean you can calculate it yourself too if you want. The equations for projectile motion is this. X0,y0 is the start position, x1,y1 is the end position, vx,vy is the launch velocity, a is the gravity, and t is the flight time. You can then use algebra to solve for the unknowns.

    X1=X0+vx*t

    Y1=Y0+vy*t+0.5*a*t*t

    But anyways. With the physics behavior it should still work. Just set the velocity on launch and you won’t have to worry about mass. With damping at 0 it should be flawless, but damping in general would throw it off. I don’t know if anyone worked out how damping is done to work with that.

    Maybe you’re making a typo or something when adapting that example to your events.

  • megatronix

    Always nice to hear the plug-in being used. Time and motivation are the main obstacles of most of my projects. But anyways.

    I’ll look up that program. There’s always interesting ways different programs do things.

    Which load action? There’s one to load an image file, one to grab a sprite texture and one to load an obj file. Obj files are a simple text based 3d model format. You could probably generate a file from the vertices. Just save the xyzuv of the vertices to an array as you add them. Then you’d add two lines for each vertex in the file: “v x y z”&newline&”vt u v”&newline. Then you’ll need to add the faces. Every three vertices define a face so this would generate the face data:

    Var i=0
    Repeat int(vertexCount/3) times
    — set i=loopindex*3+1
    — append “f “&(i)&”/“&(i)&” “
    — append (i+1)&”/“&(i+1)&” “
    — append (i+2)&”/“&(i+2)&newline

    Collisions are a can of worms. Storing all the xyz’s of the vertices is the first step. Then if you transformed the object using that mesh at all you’ll need to transform those points too. Basically xyzVector *scaleVector *orientationMatrix+positionVector. After that, each group of three vertices define a triangle. And after that… I guess it depends on what kind of collision detection you want. There are a lot of algorithms different algorithms and I can’t do them justice off the top of my head. Tri vs Tri could be done with SAT, MPR, GJK or maybe calculating the line where the two planes making up the triangles intersect, clipping the line by the edges of both triangles and if there’s anything left it’s a collision. Those first three algorithms work with all the points of convex solids and will give some collision info such as normal vector and where.

    I don’t think I’m scratching the surface though. In general to make things faster you’d use a simpler collision mesh instead of the visual one, or approximate it with simpler primitives like spheres, bounding boxes, oriented boxes, capsules, height maps etc. However in the construct realm I think the simplest solution is just do all the collisions in 2d and have the 3d just be a visual. You can look at any 3d collisions people are doing in c3 for some ideas too.

    The process for implementing any of that is to find an algorithm online somewhere and adapting that to events. I can only give an overview here atm.