[Behavior] gravitation (for physics behavior)

Post your completed addons to share with the community

Post » Thu Dec 06, 2012 9:27 pm

Nice plugin!

One of the most fun an entertaining demos I've seen in a long time!
Be nice until it's time to not be nice
B
36
S
9
G
9
Posts: 293
Reputation: 6,652

Post » Fri Dec 07, 2012 12:36 am

@spongehammer

I'm not sure, you might ask @chrisbrobs , he is excellent in using physics behavior.
BTW, the mass of a physics object is calculated by size in physics behavior, not in this gravitation behavior.rexrainbow2012-12-07 00:37:52
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Sun Dec 16, 2012 7:25 am

Update:

Fix bug when set source to "No"
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Tue Dec 18, 2012 12:37 am

Awesome! We can make Angry Birds Space with this
B
34
S
8
G
3
Posts: 328
Reputation: 7,692

Post » Tue Dec 18, 2012 12:39 am

@EyeHawk

Uh, you still need physics behavior.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 15, 2013 12:06 am

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:
[code]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)) { ...
[/code]

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!
B
6
Posts: 26
Reputation: 577

Post » Fri Feb 15, 2013 2:25 am

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.rexrainbow2013-02-15 02:26:14
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 15, 2013 2:29 am

@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.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 15, 2013 10:13 am

@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.
B
6
Posts: 26
Reputation: 577

Post » Sat Feb 16, 2013 12:53 pm

@Cowdozer

Nice idea, I will think about that, thank you.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests