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 Bum

You can check out what I have here.

As you can see the speed for moving and jumping is ideal for me right now. (Maybe even a bit slower). However the friction is really annoying. I do not like a lot of drag before the bum comes to a complete stop. Also when moving to the right then instantly moving to the left, the bum keeps going right until the velocity shifts to the left. I want an instant switch over.

Another thing I'm having difficulties with is the slope. I want to be able to run up it and down it without dropping or sliding off. As you can see, you can't run up the slope and when you touch the slope anyway, you slide down. Not ideal.

My last question is if there is a way to force a background to only tile horizontally instead of tiling in all directions.

Thanks!

Here's player code:

ig.module(
	'game.entities.player'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityPlayer = ig.Entity.extend({
	
	// The players (collision) size is a bit smaller than the animation
	// frames, so we have to move the collision box a bit (offset)
	size: {x: 10, y:30},
	
	maxVel: {x: 200, y: 500},
	friction: {x: 400, y: 0},
	
	gravityFactor: 5,
	type: ig.Entity.TYPE.A, // Player friendly group
	checkAgainst: ig.Entity.TYPE.NONE,
	collides: ig.Entity.COLLIDES.PASSIVE,
	
	animSheet: new ig.AnimationSheet( 'media/player.png', 32, 32 ),	
	
	
	// These are our own properties. They are not defined in the base
	// ig.Entity class. We just use them internally for the Player
	accelGround: 400,
	accelAir: 400,
	jump: 400,
	health: 10,
	flip: false,
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		// Add the animations
		this.addAnim( 'idle', 0.09, [0] );
		this.addAnim( 'run', 0.09, [15,16,17,18,19,20] );
		this.addAnim( 'jump', 0.09, [60,61,62,63,64,65], true );
		this.addAnim( 'fall', 0.09, [75,76,77,78], true );
	},
	
	
	update: function() {
		
		// move left or right
		var accel = this.standing ? this.accelGround : this.accelAir;
		if( ig.input.state('left') ) {
			this.accel.x = -accel;

			this.flip = true;
		        this.offset.x = 8;
		}
		else if( ig.input.state('right') ) {
			this.accel.x = accel;
			this.flip = false;
		        this.offset.x = -8;
		}
		else {
			this.accel.x = 0;
		}
		
		
		
		// jump
		if( this.standing && ig.input.pressed('jump') ) {
			this.vel.y = -this.jump;
		}
		
		// set the current animation, based on the player's speed
                if( this.vel.y < 0 && !this.standing)
		{
                    this.currentAnim = this.anims.jump;
                }
		else if( this.vel.y > 0 && !this.standing)
		{
                    this.currentAnim = this.anims.fall;
                }
		else if( this.vel.x != 0 && (ig.input.state('left') || ig.input.state('right') ))
		{
                    this.currentAnim = this.anims.run;
                }
		else
		{
                    this.currentAnim = this.anims.idle;
                }
		
		this.currentAnim.flip.x = this.flip;
		
		
		// move!
		this.parent();
	}
});

});

1 decade ago by paulh

No current easy way of preventing the background map form tiling in all directions.


  friction: {x: 400, y: 0},
    
    gravityFactor: 5,

try playing around with the above values and your core gravity value .. you'll also need to change how your velocity works so there's no inertia, but you maybe able to solve it with just tweaking values?

1 decade ago by Bum

I've been playing around and I like the settings, but as you said it's an inertia problem which means setting horizontal velocity to some value to avoid the "tug" it pulls when changing direction.

Also, what about the slopes problem? As you can see touching the slope instantly slides you downward. I'd like the slope to not pull the player (or any entity) at all.

1 decade ago by alexandre

For instantaneous direction changes, have you tried resetting vel.x when current input (left or right) signals a change of direction?

(untested)

e.g., you just input "left" when your entity was moving right:
this.vel.x = this.vel.x > 0 ? 0 : this.vel.x;

In context:
update: function()
{
	// move left or right
	var accel = this.standing ? this.accelGround : this.accelAir;
	if (ig.input.state('left'))
	{
		this.vel.x = this.vel.x > 0 ? 0 : this.vel.x;  // <--------
		this.accel.x = -accel;
		this.flip = true;
		this.offset.x = 8;
	}
	else if (ig.input.state('right'))
	{
		this.vel.x = this.vel.x < 0 ? 0 : this.vel.x;   // <--------
		this.accel.x = accel;
		this.flip = false;
		this.offset.x = -8;
	}
	else
	{
		this.accel.x = 0;
	}
	//...

1 decade ago by Bum

Thanks for the info. I suppose I can figure out the inertia problem my own then. But what about the slope issue? I'd like for entities to 'not' slide down them.
Page 1 of 1
« first « previous next › last »