Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Liquidfun platformer - Page 2 - Gideros Forum

Liquidfun platformer

2»

Comments

  • MoKaLuxMoKaLux Member
    edited November 4
    -- beginning of enterframe
    local vx, vy = self.body:getLinearVelocity()
    -- lots of calculation
    ...
    -- get the linear velocity again!
    local tvx, tvy = self.body:getLinearVelocity()
    local velocitychangex = vx - tvx
    local velocitychangey = vy - tvy
    local impulsex = self.body:getMass() * velocitychangex
    local impulsey = self.body:getMass() * velocitychangey
    -- impulse
    self.body:applyLinearImpulse(impulsex, impulsey, self.body:getWorldCenter())
    Before I was moving with setLinearVelocity and I thought that was the problem so now I use this method.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited November 4
    @antix sorry I just posted the code above, now that you pointed this I need to redo how I move the player. I will have another look at iforce tutorials and will let you know.
    My code above makes no sense :* but strangely it works fine.

    Thank you antix <3

    EDIT: I have tested with this code (game loop):<pre class="CodeBlock">
    vx = self.body:getLinearVelocity()
    if isleft then desiredvelx = -5 ... end
    local velocityxchange = desiredvelx - vx
    local impulsex = self.body:getMass() * velocityxchange
    self.body:applyLinearImpulse(impulsex, 0, self.body:getWorldCenter())
    self:setPosition(self.posx, self.posy)
    With no luck :'( the dynamic bodies still interpenetrate.

    PS: don't look at the naming of my variables I am just testing
    PS2: It's been days I am trying to figure this out, in my case I wanted to have some rocks fall on the player and on the ground. When the rocks have finished hurting the player and then lay on the ground I wanted the player to be able to walk over them (that was the idea).
    PS3: that's weird box2d behavior, isn't it?
    PS4: will try to post on the box2d github :)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.