# [behavior] rex_LJpotential (attracting or rejecting objects)

### » Tue Sep 02, 2014 7:10 am

@justiffun

The foumla of this behavior is
(A/(r^n)) - (B/(r^m))
For example, n=1 , m=2
A/r - B/(r*r)
Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

### » Tue Sep 02, 2014 1:57 pm

@rexrainbow

I'm not very good at math, so i was trying to figure out how changing those values affect how the objects move.

for example:
It appears that increasing "A" makes the objects attract stronger to one another
what does "n" and "m" do?
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,562

### » Wed Sep 03, 2014 1:10 am

@justiffun
The bigger n, the attracting will get smaller at the same distance.
Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

### » Fri Sep 26, 2014 8:20 am

@rexrainbow
Useful stuff as usual. Right now I'm trying to figure out one thing:

- There are two types of units: enemy units and player's units
- Enemy units are attracted to the players units and the other way around (this part is working)
- But at the same time player's units should reject other player units and the same for enemy - I can't figure out how to do it

If I change "B" from 0 to some higher value, they start to reject opponent's units. Right now I'm using Source/Target Tags for differentiation. I think the problem is that the units of the same type do not consider other units of the same type as source, and that's why rejection doesn't work. I'm gonna try to use groups for differentiation.
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

### » Fri Sep 26, 2014 8:40 am

@xoros

Yes, tag system in this behavior has limitation. That's way I add instance group supporting (calculation manually) for advance. Moreover, user could rest A,B,n,m before calculation.
Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

### » Fri Sep 26, 2014 10:00 am

I tried to set Attraction Parameters on runtime - but there's no possibility to set a number: "SetLJpotential LJ parameter" - only a pulldown menu with parameter
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

### » Fri Sep 26, 2014 10:08 am

@xoros

Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

### » Fri Sep 26, 2014 10:38 am

Cool
B
45
S
11
G
4
Posts: 517
Reputation: 7,398

### » Fri Sep 26, 2014 11:12 am

@rexrainbow
Hmm, still can't figure out how to reject the same unit type and attract to the opposite units. Basically it's like magnets: blues reject blues but attract reds, and reds reject reds but attract blues.

What I'm doing right now:

- unit on created > add to the "reject&type" group, add to the "attract&type" group
- for each unit > clean force; pick "reject&type" group; set LJ potential B to 10; Attracted by source Units; set angle to force
> pick "attract&type" group; set LJ potential A to 10; Attracted by source Units; set angle to force

B
45
S
11
G
4
Posts: 517
Reputation: 7,398

### » Fri Sep 26, 2014 11:26 am

@xoros

I am not sure, will you provide a sample capx? It is also an interesting demo I guess.
Goodbye
B
111
S
28
G
295
Posts: 4,549
Reputation: 164,228

PreviousNext

### Who is online

Users browsing this forum: No registered users and 1 guest