[Behavior] gravitation (for physics behavior)

0 favourites
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Hi rexrainbow, I think this Behavior is great and appreciate that you've made it public. I was playing with it today and noticed that if you have a Gravitation object that is both a source and target for the same source/target tag, the object will apply a force on itself. The result is that it accelerates to the right all on its own.

    I needed this to work properly, because I want to have objects that pull on each other, much like planets do. I updated your plugin with a simple change that fixed the problem for my needs:

    runtime.js, ~line 150-160, function behindstProto.tick:

    var sources = this.sources[this.target_tag];
    var this_uid = this.inst.uid;
    var uid, source_inst, inst, source_grange_pow2;
    for (uid in sources)
    {
        source_inst = sources[uid];
        inst = source_inst.inst;
        
        //We do not want an object to be exerting a gravitational force on itself
        if (this_uid === inst.uid)
            continue;
              
        source_grange_pow2 = source_inst.sensitivity_range_pow2;
        if (this._in_range(inst,  source_grange_pow2)) { ...
    

    If you agree with this change and can update the master copy of the Behavior to have this change, that would be great! Also, there is a typo in edittime.js: "Traget" should be "Target".

    I'm also interested in making the force applied dependent on the distance between objects as well as the mass of the objects. Maybe we could have a ForceMode parameter where the user can choose between Constant (what we have now), Linear, and Quadratic force. I'm very new to Construct 2 and yours is only the 2nd Behavior I've looked at in code, so I'll have to learn a bit more about Behaviors and Plugins before attempting this modification. I'll keep you up to date if I come up with anything interesting, though!

  • Update:

    • excluded target when it is a source with the same tag.

    ( Thanks to Cowdozer )

    • fix typo at combo:Target in property.

    Note: it is a breaking change, please reset target object setting in properties table.

  • Cowdozer

    I had made linear, and quadratic force before, but the effect is not good enough.

    The target will be applied a very big force when the distance between source and target is very very small.

    You could try it by modified this plugin.

  • rexrainbow

    Thanks for applying the update so quickly! Yeah, I understand that a linear or quadratic force function will return very large numbers when the distance between objects is very small. At first I was surprised that your simulation wasn't doing that, and then I realised that you were applying a constant force. :p To prevent excessively large forces, you can cap the force at some maximum value, or use a slightly different function that doesn't approach infinity at 0.

    For example, if the function for f at distance d was f(d) = 1/d, then f(0.001) is very large. But if instead our function was f(d) = 1/(d+0.01), then the largest force is f(0) = 1/0.01 = 100. This is reasonable, yet is still linear and feels almost the same. The only real challenge here is finding a solution that works well for everyone who wants to use it.

  • Cowdozer

    Nice idea, I will think about that, thank you.

  • Looks awesome and I would love to try it... only problem is the download link doesn't work! PM me if you fix it <img src="smileys/smiley4.gif" border="0" align="middle" /> (pleaaaaase)

  • Great work rexrainbow!

    I'm trying to apply the behavior to a different scenario. I'd like to have a character be able to walk around a circular planet. Trouble is, as I have it now, the character falls off at soon as it gets to 0/1 degrees or 180/181 degrees.

    What's going on here? Can the behavior be used in the situation I'm trying to create?

  • bachrock

    Could you provide a simple test capx for this case?

  • bachrock

    Could you provide a simple test capx for this case?

    rexrainbow: dropbox.com/s/orch4snikw0vmez/Satelite%20and%20Source%20Gravity%20Test.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • bachrock

    The platform behavior has gravity setting. It will cause yellow ball dropping down. Set it to 0, the yellow ball will attach to red ball. You might set this value to a reasonable one.

  • Hi rexrainbow

    I am building a quick game that is a bit like that sample. However, the attraction only seems to come one rather than all simultaneously. Is that correct? Is it a bug? or perhaps I have not factored anything in.

    I have noticed in your second sample that the attraction of gravity only seems to be coming from the middle red circle as well?

  • TheWyrm

    I am not sure what you would like to know,

    I guess you might ask the attracting distance -

    [quote:fswd3xtb]"Sensitivity range" property which is the maximum distance between source and target to gravitate, 0 is infinity.

    BTW, the document of this behavior had be re-wrote. See first post of this thread.

  • I was trying to work out if multiple sources could apply force to the target at the same time. So the force applied to the target would be a combination of both velocities. In your sample2 capx it looks like only one source force can be applied to the target at one time.

    Fiddling with sensitivity sorted the problem in my game, but I would be interested in an answer to the above.

    Great plugin by the way

  • TheWyrm

    Only "source tag" == "target tag" will be attracted, like this capx (capx 2).

    Edit:

    Would you like to have more flexible about attracting sources selecting?

  • rexrainbow Sure, but in that capx you have three sources with the same tag. So either;

    1. They all work simultaneously.

    OR

    2. One of the sources takes priority.

    I want to know which? I was hoping for 1 but I think it's 2.

    If it is 2 then which source takes priority?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)