Class gravityBehavior does not exist!!

Hello all I just started using toxiclibs and I'm a new user of processing(so not much experienced :) ) I'm getting and error while using a physics 2D behavior. I'm following nature of the code tutorials.

import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
VerletPhysics2D physics;

void setup() {
  size(800, 600);
  physics = new VerletPhysics2D();
  physics.setWorldBounds(new Rect(0, 0, width, height));
  physics.addBehavior(new GravityBehavior(new Vec2D(0, 0.5))); 
} 

and I get this error that the class gravity behavior does not exist. Somehow stuck. I would appreciate if someone help me with this.

Answers

  • Hello

    I found this code in samples from toxiclibs, and the system doesn't point "GravityBehavior2D" as an error, besides it works. Check it out

    import toxi.geom.*;
    import toxi.physics2d.*;
    import toxi.physics2d.behaviors.*;
    
    int NUM_PARTICLES = 750;
    
    VerletPhysics2D physics;
    AttractionBehavior2D mouseAttractor;
    
    Vec2D mousePos;
    
    void setup() {
      size(680, 382,P3D);
      // setup physics with 10% drag
      physics = new VerletPhysics2D();
      physics.setDrag(0.05f);
      physics.setWorldBounds(new Rect(0, 0, width, height));
      // the NEW way to add gravity to the simulation, using behaviors
      physics.addBehavior(new GravityBehavior2D(new Vec2D(0, 0.15f)));
    }
    
    void addParticle() {
      VerletParticle2D p = new VerletParticle2D(Vec2D.randomVector().scale(5).addSelf(width / 2, 0));
      physics.addParticle(p);
      // add a negative attraction force field around the new particle
      physics.addBehavior(new AttractionBehavior2D(p, 20, -1.2f, 0.01f));
    }
    
    void draw() {
      background(255,0,0);
      noStroke();
      fill(255);
      if (physics.particles.size() < NUM_PARTICLES) {
        addParticle();
      }
      physics.update();
      for (VerletParticle2D p : physics.particles) {
        ellipse(p.x, p.y, 5, 5);
      }
    }
    
    void mousePressed() {
      mousePos = new Vec2D(mouseX, mouseY);
      // create a new positive attraction force field around the mouse position (radius=250px)
      mouseAttractor = new AttractionBehavior2D(mousePos, 250, 0.9f);
      physics.addBehavior(mouseAttractor);
    }
    
    void mouseDragged() {
      // update mouse attraction focal point
      mousePos.set(mouseX, mouseY);
    }
    
    void mouseReleased() {
      // remove the mouse attraction when button has been released
      physics.removeBehavior(mouseAttractor);
    }
    
  • Answer ✓

    the system doesn't point "GravityBehavior2D" as an error,

    Ha, this is useful information in perhaps a way that you hadn't intended... The original is using GravityBehavior and not GravityBehavior2D. Error might be a typo, might be an old example.

  • The problem was the compatibility between the processing version I'm using for and toxiclib version. I used version 19 and downloaded directly from the toxiclib official website and the error is gone now :)

  • Yeah koogs thats true. Thanks

Sign In or Register to comment.