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 Hareesun

I'm trying to implement something along the lines of crouching, but have hit a block that I can't figure out. Just wondering if anyone else has tried and succeeded?

Whats happening is when the key is down the size changes and sits on the ground fine, but then letting it go to restore the original height seems to push the entity through the floor.

Here's what I've got so far...
EntityCroucher = ig.Entity.extend({
  size: {x: 6, y: 26},
  
  ...
  
  update: function() {
  if (ig.input.state('crouch')) {
    this.size.y = 13;
    } else {
      this.size.y = 26;
    }
  }
  
  ...

});

Any help is greatly appreciated

1 decade ago by jminor

The origin of an entity is the top-left. You probably need to move the entity down/up by 13 pixels when you crouch/un-crouch.

1 decade ago by Hareesun

Uh. Can't believe I didn't think of that. :! To be concise, this is what I did.

if (ig.input.state('crouch')) {
    this.size.y = 13;
} else {
  this.pos.y = this.pos.y - 13;
  this.size.y = 26;
}

1 decade ago by BFresh

That's exactly what I did, seems to work well. The 'jerkyness' of the screen centered on the player was bugging me when I resized the player and moved his position though, so I center the screen on player pos.y+size.y to stay on the bottom of the character and it seems to be smooth.

1 decade ago by SpaceHorse

so, i can't understand. it does't work in my case.
i'm trying
                if (this.crouch)
                {
                    this.size.y=3;
                }else
                {
                    this.size.y=14;
                }

in update of player. but it doesn't work. the player can't get thru tighter (smaller) holes in map. now it can only go thru holes like which size is more than 14 px. but i have to make it somehow to let him go thru smaller holes.
also wanted to mention that i used Physics BOX2D example as basic. maybe everything works another way there. i dont know.

1 decade ago by SpaceHorse

So, i checked everything and what i want to say:
if (ig.input.state('crouch')) {
    this.size.y = 7;
} else {
  this.size.y = 14;
}

works in standard engine.
and it doesn't work in "physics" example where you are working with ig.Box2DEntity but i can't find the difference.
Do you know why it could happen?

1 decade ago by MobileMark

I believe it's because Box2D takes over all collisions, so it interprets your first size and translates it to a Box2D collision map. So in order to change the size of the entity mid game, I'm assuming you'll have to reload the entities size. Unfortunately I'm not sure on the syntax.

Might be something like this? (I'm pretty sure it's wrong but might be on the right track)
ig.world.DrawShape()	;

You can check out this doc for a bunch on information about the commands in Box2D

http://www.box2dflash.org/docs/2.0.2/reference/Box2D/Dynamics/b2World.html#SetGravity%28%29

1 decade ago by SpaceHorse

Yeah, i think so too. about collisions. and i found this thing:
this.body.SetXForm(this.body.GetPosition(), this.body.GetAngle());

it sets position and angle of the collision object. Now i only have to find how to set size of my collision object. Did anyone work with it?
Page 1 of 1
« first « previous next › last »