Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how to make a one sided platform with box2d — Gideros Forum

how to make a one sided platform with box2d

alexzhengalexzheng Guru
edited November 2011 in General questions
as the demo in OneSidedPlatform.h of box2d source code.

and another question,how to determine whether the player is jumping onto some body or the player is smashed by some body falling from upside in the collision handler.
in other words,is it possible to get the force vector and force point during a collision?

Likes: dxd

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • to detail,my player should avoid the body following from upside and step onto the body to get higher position
  • atilimatilim Maintainer
    At the Event.POST_SOLVE event, the event table contains a field "maxImpulse" which is calculated as the maximum of normal impulses:
    function onPostSolve(event)
        print("maxImpulse:", event.maxImpulse)
    end
    world:addEventListener(Event.POST_SOLVE, onPostSolve)
    (Currently we don't give direct access to contact points and normals)
  • thanks for quick reply.
    is that to say it's impossible to implement my game currently?
  • You can use PRE_SOLVE, compare the positions of the player and the objects, and if the player is below, set Fixture to sensor (
    setSensor(true)
    ), and vice versa.
  • hi Stoffe
    thanks for reply.
    you are right,maybe I could determine by the positions and velocity of the player and the objects
  • Sorry, I think I misunderstood a bit, I thought you were talking about being able to jump through a platform and then land on it. The same principle holds, but if you want to check collisions like that you probably don't even need PRE or POST.

    Comparing the Y positions of the player and the object will tell you which one is higher than the other: if the players Y is (player radius + half platform height) less than platform Y, then the player is above and safe. You probably need to tune those numbers a little bit though.

    Another way to do it is to use two collision fixtures, one for feet and one for head. That's what I do, in a skateboarding game with free rotation - anything at the feet is fine, anything at the head means death.

    If you want to have the player take damage based on the impact of the collision, it might be easier to simply add the velocities involved (player + falling object) than use maxImpulse and do it in regular collision. Impacts, especially summed up, can be a bit... unpredictable, and in games it often gives better results to cheat and simplify. ;)

    It all depends on what you are aiming for. For instance, can the player collide with the falling object from the side? What happens then?

    If your problem is more complicated than that, please elaborate. :)

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • alexzhengalexzheng Guru
    edited November 2011
    use two collision fixtures is a great idea!
    by the way,I think move and rotate a movieclip using physics is not very convenient since the anchor point is not in the center. I can set the position of movieclip by using an offset to the body,but no way to set the rotation.
  • atilimatilim Maintainer
    You can put your MovieClip as a child of another Sprite and can set the position and center of rotation.
  • did you mean set center of the MovieClip to the left-top point of the parent sprite?

    mc:setPosition(-mc:getWidth()/2, -mc:getHeight()/2)
  • atilimatilim Maintainer
    and then rotate the parent sprite
  • In this link they talk about one sided platforms in Box2D and Flash.

    http://www.emanueleferonato.com/2010/03/02/understanding-box2ds-one-way-platforms-aka-clouds/

    The code there mentions to disable the contact. Is this somehow supported in Gideros?
  • atilimatilim Maintainer
    not yet. but we plan to give support to access contact information very soon.
  • Am trying to solve a very similar problem, except in my case I am trying to create a 'one-way' gate. As was suggested in previous posts to this thread I tried making the gate body fixture into a sensor in the PRE_SOLVE box2d collision event, but it simply doesn't work. The ball still bounces off the gate as if it was solid.

    Having access to the contact information and the ability to simply disable / ignore it if the ball is found to be on the correct side of the gate ( determined with a bit of vector maths as the gates could be arbitrarily oriented ) would be really useful.

    At the moment I am left with trying to find another way to achieve the effect. Any suggestions?
  • atilimatilim Maintainer
    still we don't support accessing contact information in collision events. I don't know if there is another way of achieving this effect.
Sign In or Register to comment.