R0J0hound's Forum Posts

  • angryscientist

    I won't be able to add that since i'm not working on this anymore.

    delgado

    I don't use parallax, but it is something you can do via events. Basically just move the object from one layer to the other, paste, and then move it back. Something like this:

    global number oldLayer=0

    global number oldX=0

    global number oldY=0

    global number x=0

    global number y=0

    set oldX to sprite.x

    set oldY to sprite.y

    set oldLayer to sprite.layer

    set x to LayerToCanvasX(sprite.layer, sprite.x, sprite.y)

    set y to LayerToCanvasY(sprite.layer, sprite.x, sprite.y)

    Sprite: move to layer canvas.layer

    Sprite: set position to CanvasToLayerX(canvas.layer, x, y), CanvasToLayerY(canvas.layer, x, y)

    canvas: paste sprite

    Sprite: move to layer oldLayer

    Sprite: set position to oldX, oldY

  • Same issue as dop2000. The forum is dog slow now. I get the idea that websites aren't Scirra's expertise.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's the fx:

    It's used apart from the canvas plugin.

    The only useful action in the canvas plugin would be the "paste object" action. You could use it to stamp the sprites onto the canvas. You could then give the fx to the canvas. The paster plugin could be used instead, it's a bit different but solves some performance issues canvas had.

    Another option is to just have the sprites on a layer and have the layer have the fx.

  • If you're happy with a solid outline you could use the outline effect.

    For a dashed line you'd need to calculate the outline from the intersection of the shapes. The canvas plugin gives a way to draw it after you calculate it, or you could use a tiled background for each edge.

    It's not super trivial to calculate but a lot of solutions can be found online that can be adapted over.

  • link updated

  • Link updated.

  • RattyRat

    You could also look at another paid for box2d plugin. I think they have that feature there.

    A game engine from scratch is more appealing than unity. At least to me.

  • Stopping distance would be = (speed^2)/(2*deceleration)

  • I had a look around at some other implementations for buoyancy that can give some more ideas.

    https://github.com/lawrencelomax/Chipmu ... Buoyancy.c

    The damping force was calculated with the relative velocity of the part under water. I forgot to do that in the examples.

    The angular damping is proportionate to the inertia of the shape under water. Could give improved results.

    http://www.iforce2d.net/b2dtut/buoyancy

    Again it uses relative velocity for damping.

    It has a cool idea to do the damping per edge to give more realistic results.

    Also it shows ideas how to take the whole thing further with lift. Very interesting.

  • RattyRat

    You can't do that with the plugin, and modifying it to do so will have lots of caveats. The idea came up when I was making the behavior but I opted for making things easier to use. It's something best served by a ground up re-write and re-design of how it deals with the js library. I'm not really modifying or creating plugins or behaviors lately though. Lots of work for little gain imo. I have other more entertaining and interesting projects i'd want to do first, but if those succeed I may not be back.

    Anyways, the behavior manages the conversion of c2 coordinants to chipmunk coordinants, and vise versa. The complication is c2 uses the origin as the object center and chipmunk uses the center of mass (COM). To have multiple objects welded together they'd have a shared COM, and it would have to be updated every time things are moved with anything but the physics engine. There are other properties that would need to be updated as well. At least that's my thought.

    -cheers

  • i have an old example the you may be able to find that uses a JavaScript physics engine directly to do hand drawn shapes. The drawback is you have to do all physics objects that way. The behaviors don’t interact with it.

    There’s also a sold physics behavior that lets you do that. That’s all I know, I avoid buying stuff.

    A third way would be to modify one of the existing behaviors but this is out of scope to most.

  • I’m on my phone but offhand:

    The calculated area will be zero when there’s no overlap. So the forces will evaluate to zero too because they are multiples by the area.

    I just kind of threw the three examples together, but the idea is to just tweak the numbers in the equations. I think I tried something different for the chipmunk damping maybe that’s no good?

    The two behaviors have many differences. I made no effort to match them up.

  • All three examples just vary by the amount of linear damping, angular damping and amount the area affects the force. You can tweak all three to get things closer.

    For other shapes just add more image points, and make sure you place them in a clockwise order. Then in events 4 and 5 there are 4's, replace those with imagepointcount+1. You were halfway there.

    What do you mean connect things together? That would just be joints and is unrelated to the buoyancy here.

  • Here's my solution.

    1. Take the object polygon and slice it by the water level to get the polygon of the area underneath.

    2. calculate the area and center of that area.

    3. Apply a buoyancy force proportionate to the area and do it at the calculated center.

    4. Apply some damping to the object to slow it's velocity when in water. This corrects the bouncing.

    3 and 4 will differ depending on what you use. I tried event based physics, chipmunk and the physics behaviors.

    https://www.dropbox.com/s/5gllhncklyzsp ... .capx?dl=1

    https://www.dropbox.com/s/1b95mjd4viv8d ... .capx?dl=1

    https://www.dropbox.com/s/3539qrtyc0l7c ... .capx?dl=1

    I didn't try to get each to be identical, tweaking the numbers in the last event can adjust the result.

    A few notes:

    * To make the objects sink more apply a lower force.

    * damping is done by applying a force opposite a fraction of the velocity. Too high of damping can cause the object to actually speed up.

    * angular damping was a bit more tricky. I found more damping is needed than with linear damping. There also appear to be some better approaches but they add complexity and so far the results seem "good enough."

    Also as a reference, here is a list of the units the Physics behavior uses.

    math-and-physics_p821290?#p821290

  • The realistic way would be to find the area of the object under the water and apply a force proportional to that area, and from the center of that area up.

    As a simple example let’s look at a non rotating box.

    Area = box.width * clamp(box.bottom-water.top, 0, box.height)

    Apply force up with magnitude area

    In the general case with any shape with rotation you could take the polygon of the object, slice it by the water level, and find the area and average center of anything below. I forget if the physics behavior

    Let’s you apply a force at any point of the object but that should take care of any torque if it does. If it doesn’t then you can take the vector from the com to the point to apply the force and do a cross product with the force vector. Maybe some unit conversion would be needed, I don’t recall.

    It’s an interesting enough problem I may attempt an example capx over the weekend. The bulk of it will be finding the area under the water.