Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by dlkulp

the error is on line 467 of lib.js in the box2d plugin. changing it to:
if(typeof global != 'undefined' ) global.Box2D = Box2D;
fixes the error.

with strict enable the previous way fails as global does not exist, thus it's value cannot be checked. typeof always returns a string of the current falsy value which solves the problem!

1 decade ago by Joncom

@dlkulp: I don't seem to experience this error. Can you tell me how to replicate it?

1 decade ago by dlkulp

I copied your files into a subdir of plugins called joncom/box2d/. In my main.js I require game.entities.player and plugins.joncom.box2d.game. In player I require only plugins.joncom.box2d.entity. I thought that maybe it was an error with code I had written with plugins.box2d not being properly switched so I undid the renaming and tried removing the joncom folder and just having it be plugins.box2d as I had originally had it (before finding your nice little plugin) but that didn't help either. In the end the only thing that worked was what I pointed out above with the difference between the falsy value of 'undefined' and simply being not defined. It didn't seem to matter what else was in those two files (main and player) and would just continue to error out.

1 decade ago by Joncom

@dlkulp: Oh OK, now I see. Thanks for pointing that out! Fixed.

1 decade ago by dlkulp

Alright, thanks for being so quick and responsive! Always nice to see active work on a cool project!

10 years ago by JrJungle56

Box2D Sugar version is great, a bit of a learning curve as all the documentation online is geared towards the normal syntax, but once implemented it works great; used it on my last game

9 years ago by mimik

@Joncom not sure if you are still updating this but standing dosent work.

9 years ago by Joncom

@mimik: Able to provide a simple example containing the issue?

9 years ago by Dejan

@ Joncom I actually, some time ago, experienced the same problems with this.standing when I in the middle of a project decided to change everything to box 2d.

After trying a little bit I noticed that standing is becoming true if you rotate the character a little bit. So in fact this.standing stayed false as long as the character was normaly standing. If your character for example was lying on the ground standing changed to true. And while lying on the ground this.standing started to normally work again. So jumping while lying on the ground chnaged this standing back to false the way it should be.

so imagine the problem being like https://dl.dropboxusercontent.com/u/51029492/error.jpg

I suppose mimik could have expirience the same problem

9 years ago by Joncom

Actually this has come up before. Fix here. Although it only seems to effect some people for some reason.

9 years ago by substandardgaussian

Joncom, I've run into the standing issue too. I seem to get different normals at different times.

When I start with my PC on the floor, I see a normal.y of -1, but after a jump the normal.y becomes 1. When starting in the air in WM, and letting my PC fall to the ground when the game starts, I get a normal.y of 1 after I land.

I'm under the impression that the "fix" only works sometimes or is entirely unnecessary because of this erratic behavior. Originally, I was able to jump exactly once, and then never again, since the normals I was seeing flipped signs and stayed that way.

EDIT: On reviewing how contact manifolds are stored, it seems that the normal is stored pointing from the "first" shape to the "second" shape, where "first" and "second" are determined by the order those shapes are stored in the contact.

You're checking the normal without checking which fixture is stored first, and therefore which way the normal should point. This is why the "fix" works sometimes but is erratic. It all depends on the order in which the contact object is populated by the shapes it contacts, which presumably has a logic that remains reasonably consistent from timestep to timestep. This is why I was originally only able to jump once: when the level was loaded, the ground happened to be stored first in the original contact, but once that contact was destroyed and then created again once my player touched the ground, the player was stored first.

A general fix would be something like:
     var normal = edge.contact.m_manifold.m_localPlaneNormal;
     if (edge.contact.GetFixtureA().GetBody().entity == this) {
         console.log("First entity is player");
	  if (normal.y > 0) {	
               return true;
	  }
      }
      else {
         console.log("First entity is ground");
	 if (normal.y < 0) {
	      return true;
	 }
      }

9 years ago by Joncom

Quote from substandardgaussian
You're checking the normal without checking which fixture is stored first, and therefore which way the normal should point. This is why the "fix" works sometimes but is erratic. It all depends on the order in which the contact object is populated by the shapes it contacts, which presumably has a logic that remains reasonably consistent from timestep to timestep.
Hey substandardgaussian. Nice find! Thanks for pointing that out. Added your fix.
Page 2 of 2
« first ‹ previous next › last »