Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411532 Posts in 69382 Topics- by 58438 Members - Latest Member: isabel.adojo

May 02, 2024, 11:37:02 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Box 2d Platform game problem
Pages: [1] 2
Print
Author Topic: Box 2d Platform game problem  (Read 6037 times)
Sigma
Level 1
*


View Profile WWW
« on: October 19, 2009, 09:14:00 AM »

Hi friends,

    I'm currently working in a as3 platform game that uses box 2d for physics. Everything works fine. but the thing is whenever my player collide with a moving platform from the sides my platform starts vibrating as it moves and i couldnt stop the vibration. Even i applied some force to stop the vibration but still it vibrates.

In the below code force to apply is the velocity vector of colliding object and mass is its mass.

public function stopFlickering(forceToApply:b2Vec2, mass:Number){
         forceToApply.Multiply(1/Main.FRAME_RATE);
         forceToApply.Multiply(mass);

         _body.ApplyImpulse(forceToApply, _body.GetWorldCenter());
      }

Help Me Guys !!!!!!!!
Logged

John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #1 on: October 19, 2009, 09:27:27 AM »

Not enough information. Box2D is very complicated and there are a lot of ways to create a moving platform. Without knowing how you did it, I can't comment on why it isn't working.

Also, introduce yourself:
http://forums.tigsource.com/index.php?topic=45.0

Alternatively, direct your question (with more information) towards the official Box2D forums:
http://www.box2d.org/forum/
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #2 on: October 19, 2009, 09:34:42 AM »

hi john have any tutorials on moving platforms in box 2d?
Logged

bateleur
Level 10
*****



View Profile
« Reply #3 on: October 20, 2009, 01:21:49 AM »

Even i applied some force to stop the vibration but still it vibrates.

You could try setting the velocities directly (m_linearVelocity and m_angularVelocity fields of the b2Body).

Or if that's too hacky for you, it may be possible to use the built-in damping support to stop the vibration [Disclaimer: I've never actually tried this!].
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #4 on: October 20, 2009, 03:26:31 AM »

Thanks bateleur,
            Actually i set the velocities directly still it didnt work. But m_linearDamping rocks !!! It solved the problem. Actually i dont know what is linear damping? Could u please explain?
Logged

B. van Stokkum
Level 0
***



View Profile
« Reply #5 on: October 20, 2009, 04:49:51 AM »

A linear system's output is proportional to its input.

As for damping?  Upon impact, systems won't come to immediate rest.  You'll see some oscillation in the form of bouncing usually;  even a heavy object, like a car, will bounce to some extent if it falls off a cliff.  Damping attempts to reduce these oscillations to control or prevent them.  The shocks in a car are a damping system.

You can read more about it:  http://en.wikipedia.org/wiki/Damping
« Last Edit: October 20, 2009, 04:54:44 AM by B. van Stokkum » Logged
Sigma
Level 1
*


View Profile WWW
« Reply #6 on: October 20, 2009, 08:57:01 AM »

Thanks van Stokkum for the Reply.

    Now i have another problem. I have different actions for my character under different labels. When my character is in standing pose its width is 20 pixels when it is running the width is 80 pixels. but the width of my physics body is 10(i.e half width in terms of box 2d). so for i worked only with the standing pose everything worked fine. Now when i change the standing pose to running pose things are going weird. Is there any limitation that all the animations of the movieclip attached to the body should be within the boundary of the body. i stored my movieclip data in _body.m_userData. Help me guys...
Logged

John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #7 on: October 20, 2009, 04:37:06 PM »

No, Box2D doesn't care at all about the width of your movie clip. It does not inspect the userData, and the userData doesn't even have to be a sprite. The sprite has no influence on the physical behavior of Box2D.

That said, if you're trying to change the width of the Box2D shape, that will fail. If you want the physical width to change, you need to remove the old shape from the body and add a new one (and probably SetMassFromShapes() again).

Also, do not use pixels as your distance units. As a rule of thumb, 40 pixels per Box2D distance unit is pretty good. So a sprite that is 20 pixels wide should have a box that is 0.5 units wide, or 0.25 for the half width.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #8 on: October 20, 2009, 09:59:44 PM »

Thanks john i think the problem is with the position of the movieclips placed inside different labels. I think everything should be centre aligned properly. because im not only using the body position im using the _body.m_userData.x and y also for some calculations. Lets see...
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #9 on: October 21, 2009, 05:38:35 AM »

Thanks for the help so for guys...
The problem is with the position of the movieclips under each labels as suspected. some are aligned to centre and others are not so...
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #10 on: November 10, 2009, 02:45:57 AM »

Hi Guys,
       How to clear a box 2d debug? after the end of a level i have deleted all the bodies in my world and even i set the world to null still the debugs are visible.All helps are appreciated
Logged

bateleur
Level 10
*****



View Profile
« Reply #11 on: November 10, 2009, 03:04:01 AM »

In AS3, Box2D draws to a Sprite you supply. So if you want to remove what it's drawn you can always do something like debugSprite.graphics.clear(). (Replace with whatever your debug Sprite is called.)
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #12 on: November 10, 2009, 03:46:52 AM »

Thanks for the reply...
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #13 on: November 10, 2009, 04:00:26 AM »

whether page file usage affect game performance? i ran my game and noticed it in task manager under performance tab. whenever im restarting my game or loading a next level the pf usage increases by two mb. is it a issue in code? i have cleared all of my bodies and its associated event listeners.
Logged

Sigma
Level 1
*


View Profile WWW
« Reply #14 on: November 10, 2009, 11:52:32 PM »

Problem with character and ladder in a platform game. When the character collides with a ladder(through persist() in contactListener) i just set a boolean variable ( _onLadder:Boolean ) to true in the character class. The character class also have a update function which will be called every frame. So during update if the _onLadder is true it will call a method called climbUpTheLadder();

private function climbUpTheLadder():void
{
var idealLocation = new b2Vec2(_body.m_userData.x, _body.m_userData.y + (TRAVEL_SPEED * _climbingDirection));
var directionToTravel = new b2Vec2(idealLocation.x - _body.m_userData.x, idealLocation.y - _body.m_userData.y);

directionToTravel.Multiply(1 / Environment.RATIO);
directionToTravel.Multiply(Main.FRAME_RATE);

_body.SetLinearVelocity(directionToTravel);
}

till this everything works fine...

Now i need to keep the character in the xPos of the ladder whenever the character is climbing

so i just adds this _body.setXform() at the end of this climb function

_body.SetXForm(new b2Vec2(_ladderPosition.x, _body.GetPosition().y), 0);

Now the thing is even though the contact between character and ladder were removed, persist() in contact listener is keep
on calling and i set the bool var to false through remove() in contact Listener(this remove was called only once and then it starts calling persist). But i didnt call any of the function that will change the physics property of _body in contact listener i just sets a bool variable and handling everything in update function of character.

Need Help................
« Last Edit: November 11, 2009, 02:13:51 AM by Sigma » Logged

bateleur
Level 10
*****



View Profile
« Reply #15 on: November 11, 2009, 06:39:34 AM »

Now the thing is even though the contact between character and ladder were removed

It was? How?
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #16 on: November 11, 2009, 01:27:07 PM »

You get one persist every frame you are in contact with the ladder. Are you getting more than that?
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #17 on: November 11, 2009, 09:32:48 PM »

ya i'm getting more than once
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #18 on: November 12, 2009, 12:31:44 PM »

Sorry, I meant to say one persist per contact per frame, I'm already forgetting how the 2.0 API works as a work on it's replacement. So for a single box shape, you'd actually expect two contact points (one shape-shape contact can have 0,1 or 2 contact points).

It should still be the case though that you get no persists when the shapes are not in contact.
Logged
Sigma
Level 1
*


View Profile WWW
« Reply #19 on: November 12, 2009, 09:21:25 PM »

Thanks for the reply guys...
Logged

Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic