R0J0hound's Recent Forum Activity

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hit enter, or right-click -> wrap selection.

  • Here's a rough reference on loading and saving binary files. Untested but it has the relavant sources. In the examples i skipped over some more robust error checking and cross browser compatability.

    Ajax way

    https://developer.mozilla.org/en-US/doc ... ng_Started

    https://developer.mozilla.org/en-US/doc ... rrayBuffer

    https://stackoverflow.com/questions/234 ... -a-browser

    xhttp = new XMLHttpRequest();
    xhttp.responseType = 'arraybuffer';  //default is text
    xhttp.open('GET', 'old.eps');
    xhttp.onreadystatechange = function()
    {
    	if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) 
    	{
    		var byteview = new Int8Array(xhttp.response);
    		// do stuff. view is an array of bytes.
    		
    		saveByteArray([byteview], 'new.eps');  // from the third link above
    	}
    }
    xhttp.send();
    [/code:1w600qbz]
    
    nwjs way
    [url=https://nodejs.org/api/fs.html]https://nodejs.org/api/fs.html[/url]
    [url=https://nodejs.org/api/buffer.html#buffer_class_buffer]https://nodejs.org/api/buffer.html#buffer_class_buffer[/url]
    
    [code:1w600qbz]
    fs = require('fs');
    
    fs.readFile('test.eps', (err, data) => {
    	if (err)
    		throw err;
    	// do something with data.  data is an array of bytes
    	fs.writeFile('test_modified.eps', data, (err) => {
    		if (err) 
    			throw err;
    	});
    });
    [/code:1w600qbz]
    
    As for the eps file format itself i found this:
    [url=http://www.fileformat.info/format/eps/egff.htm#EPSF-DMYID.2]http://www.fileformat.info/format/eps/e ... SF-DMYID.2[/url]
    an eps file can either be all text or start with a binary header showing where things are in the file: the text ps portion, and a wmf and tiff portion which is a simple thumbnail of what the image looks like.
    
    I'm guessing the metadata you want to add would be lines that start with "%".  So you could look at the header, get that portion of the file (which is all text) and add additional lines in.  Looks like they would have to be after the initial % line as that has special meaning, also the text would have to jeust be ascii per the spec it look like.  Then before saving the file you'd have to redo the header with the new sizes and offsets of everything.  So you'd probably have to create an entirely new buffer to save to.  Seems kind of low level but the links about buffers should be an acceptable reference.
    
    Anyways perhaps some of that is useful.  I'll be sure to use it as a reference later regardless.
    
    Edit: i suppose i did skip the part on how this can be used.  Typically it would be done in a plugin or with some clever usage of the browser execjs action.  Debugging with either has a learning curve but it can be done.
  • This seems to work well:

    Set scale to 0.5*OriginalWindowWidth/min(min(camera.X, layoutwidth-camera.X), min(camera.y, layoutheight-camera.y)*OriginalWindowWidth/OriginalWindowHeight)

    min(camera.X, layoutwidth-camera.X)

    and

    min(camera.y, layoutheight-camera.y)

    are the closest x and y distances to the edge of the layout

    using the aspect ratio I can then convert the y distance to a x distance:

    y*OriginalWindowWidth/OriginalWindowHeight

    So now there are two x distances, and we can get the smaller one with another min.

    min(x, y*aspectratio)

    and to convert the x distance to a scale we multiply by 2 and divide by the window width:

    2*xdist/originalWindowWidth

    As an additional idea you can also limit the zoom if it gets much too close near edges.

    min(scale, 4)

    or whatever max scale you want.

  • I don't use nwjs, but I tried loading a binary file with ajax and saving it with the browser object. The file doesn't load. It looks like saving and loading as text will not work. Nwjs saves and loads as text as well.

    To save and load as binary will require an entirely new plugin to do so or to use javascript to do it in the browser execjs action. There's a fair amount of stuff to look up to do that.

    But then if you get past that, there's the matter of modifying the file in a way that doesn't break it. It depends on how the file format is laid out.

  • It’s a bad idea to add data to a file like that. It would

    Break it. The write file feature focuses on text files but that’s not the issue. Basically you need to know or have a JavaScript library know how the data is stored in the files. And even then many formats don’t allow you to add unrelated data in it.

    Here’s a different idea. You could create your own file in the folder and store the extra data there.

  • I’ve done x0 for first, and x1 for last. Or xi for initial x and xf for final x.

    I’ve used x0 from previous, x1 for current and x2 for next as well.

  • The chipmunk physics behavior is another way. You just specify the uid of the other object to connect to with it.

  • You have your on function events and then events right after that. Those right after aren’t part of the function event, so they will run as normal. So it’s not a case of the function triggering, it’s just events running as normal.

    If those events were sub-events I’d the function then they would be part of the function and wouldn’t run without the function being called.