1 decade ago
by bionur
Hi everyone!
I am trying to implement box2D in my game where the character should run and when i stop running however the character keeps on sliding though not running in the same direction. I looked for the solution in some forums and what i have come to was a friction to be changed. But nevertheless i cant work out how to change the friction in impact which implements box2D...:(
Any suggestions would be highly appreciated.
Thank YOU!!!
1 decade ago
by Alex
Hi,
I'm new here, but I've found out which line of the code you can play with to change this. Go to /lib/plugins/box2d/entity.js and on line 41 remove two slashes before spadeDef.friction and change it to 10 and see the results :)
edit: check box2d manual here, has more info on friction.
http://www.box2dflash.org/docs/2.0.2/manual
1 decade ago
by bionur
Hi Alex i have tried already what u showed me but the thing is that when i start running my hero starts bouncing a little with i put the friction to 10 and tried to find solutions in other forums of Box2D but still cant come up with a bright solution. Manuels also say that i gotta change the friction but it makes my hero bounce or even rotate if i put higher friction values....
1 decade ago
by bionur
Hey Alex i found the solution though i am not sure if that is the right one when a hero stops running i just put this.body.SetLinearVelocity(0, 0) which stops the hero at once but got another problem with jumping. i cant find out how to know if the hero is in the air or on the ground as long as Box2D is not fully compatible with impact's Entity class do u have any idea?
1 decade ago
by Alex
Hi,
I'm not really sure. I'll be working on movement/friction issue with Box2D myself in couple of days. As for now I found some links that might be useful -
http://www.box2d.org/forum/viewtopic.php?f=3&t=4733
http://forums.tigsource.com/index.php?topic=7431.0
P.S. - In Impact documentation I've found a ".standing" property, maybe this will help. But not sure how will it work with Box2D
http://impactjs.com/documentation/class-reference/entity#standing
1 decade ago
by bionur
Well yes i thought so about standing but that is not compatible with box2D implementation as long as it didn work with my if tests
lololo. i'm fucking with the same problem atm. I figured out how to check if player is standing (it's when velocity.y=0) and also i made him running like thru setvelocity(). but the thing is it works super glitchy atm. for example the player could just stuck in wall.
I guess the biggest problem i have with running atm is that i can't check collisions. Like i can't check what is in front of a player. it because ImapctJS has it's own collision model and Box2d has another. and i just didn't find how to ,for example, check if there is anything (object) on (x,y) position or not.
You run "b2.ContactListener" topic, maybe it could help.
or, maybe i was wrong. maybe it should be done thru friction. I mean to avoid sliding.
1 decade ago
by bionur
Yes man i got it work after subclassing b2.ContactListener in my update function inside my entity of that player now i can figure out the collision and set the flags according to it but here comes another problem with it. I want to find out the collision points like my player can pull the boxes if he collides in front or he can crawl up the boxes if he collides with the box over it so i gotta find out this collision coordinates in reference with my player. Here is a useful link man u can check it out. U can even download the code which helps u to develop ur own code snippets:
1 decade ago
by bionur
Wow! This video is just what I was looking for. This should all be placed in the docs. A shame that it isn't right now.
Went through the video to build properties into a character (namely friction). Can't seem to get this working. Spits out error: b[0] is undefined. Can't figure out what in the world that means.
createBody: function() {
var charDef = new b2.BodyDef();
charDef.position.Set(
(this.pos.x + this.size.x / 2) * b2.SCALE,
(this.pos.y + this.size.y / 2) * b2.SCALE
);
// Extra data for collisions
charDef.userData="CHAR";
this.body = ig.world.CreateBody(charDef);
// Define shape properties
var shapeDef = new b2.PolygonDef();
shapeDef.friction = 0.3;
shapeDef.density = 1;
this.body.CreateShape(shapeDef);
this.body.SetMassFromShapes();
}
Page 1 of 1
« first
« previous
next ›
last »