p5play
p5play copied to clipboard
sprite repel function
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());
}
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.
@wwjd1234 This seemed like a good idea, did you make any progress?
I will add this in v3!
Added the moveAway
function to v3.2.3