GDevelopApp / GDevelop-extensions

Repository of behaviors, actions, conditions and expressions to be used in GDevelop for creating games
https://gdevelop.io
MIT License
131 stars 53 forks source link

[Boids] Cohesion force causes Boid objects to lose position awareness and stop heading toward a target object #701

Closed tristanbob closed 1 year ago

tristanbob commented 1 year ago

Describe the bug of the extension

[Boids] Cohesion force causes Boid objects to lose position awareness and stop heading toward a target object

https://liluo.io/instant-builds/781fd186-b42c-4a61-ba63-c9f7a1d5e547

https://user-images.githubusercontent.com/8879811/208812778-6a566ced-dd65-4bad-ab05-ded36f44a378.mp4

To Reproduce

Steps to reproduce the behavior:

  1. Add two boids to your scene
  2. Use a non-zero value for cohesion
  3. Add a target for the boids to head towards
  4. Once boids get close enough for the cohesion force to apply, they stop heading towards the target.

Project files

BoidsCohesionBug.zip

Other details

tristanbob commented 1 year ago

@planktonfun Tagging you in case you are interested in this.

planktonfun commented 1 year ago

this happens because the decision weight of separation, cohesion, alignment weight are greater than or equal to "move toward object".

you can fix it by increasing "move toward object" decision weight so it can prioritize less emergent movements and more going towards the object movement.

tristanbob commented 1 year ago

I agree that when my two objects are inside the cohesion radius of each other, the cohesion force will be the same as the "move to target" force (they both use weight =1). However, in my example, the objects fly near each other (inside the cohesion radius) and then continue away (due to momentum). At this point, the cohesion force should not be applying any forces to the objects, so they should head back toward the target object. For some reason, they do not move toward the target object.

I think that the cohesion force is constantly being applied, even after the objects travel outside the cohesion radius. The direction of the force is not being updated (otherwise they would pull together). I'll try to review the code to see if I can find out where the cohesion force is applied and see if it is not being turned off when outside the radius.

planktonfun commented 1 year ago

Checked the code again, this line is missing: image

here's the updated extension with the missing line fix and cohesion fix: BoidsMovement.0.1.6.zip

debug test:

https://user-images.githubusercontent.com/1837825/209092426-6a6ce34a-abcf-4517-b6c1-49bb11492894.mp4

tristanbob commented 1 year ago

I tested this version and it works great, no cohesion bug! Thanks! Do you want to make a PR for this? If not, I can do it for you.

https://user-images.githubusercontent.com/8879811/209166435-e8fdde5c-830a-4060-9e14-ad59c740618b.mp4

planktonfun commented 1 year ago

Make PR please, thanks!

tristanbob commented 1 year ago

Fixed in #704. Thanks @D8H!