p5play icon indicating copy to clipboard operation
p5play copied to clipboard

sprite repel function

Open wwjd1234 opened this issue 4 years ago • 3 comments

I am trying to implement a repel function using

attractionPoint(-1, objectB.position.x, ObjectB.position.y)

I though by making the magnitude negative this would do it, but instead the object end up being attracted to each other.

Is there a way to do the opposite of attraction?

This only thing I could come up with is the following:

  let difference = dist(s.position.x, s.position.y, ss.position.x, ss.position.y);
  if (difference < 25 && difference != 0) {
    s.setSpeed(-s.getSpeed());
  }

wwjd1234 avatar Jan 10 '21 21:01 wwjd1234

Yep that's how it works, a negative attraction should repel the object. Feel free to post a link to a full example and I can take a look at it. By the way, objectB and ObjectB are different things.

molleindustria avatar Feb 27 '21 14:02 molleindustria

@wwjd1234 This seemed like a good idea, did you make any progress?

quinton-ashley avatar May 02 '22 23:05 quinton-ashley

I will add this in v3!

quinton-ashley avatar May 20 '22 15:05 quinton-ashley

Added the moveAway function to v3.2.3

quinton-ashley avatar Nov 04 '22 16:11 quinton-ashley