1 decade ago
by 80bit
Keeping in mind im a total beginner at this - is there some way someone could help me figure out how to 'hold' an object if, say, the shift key is held down. Im trying to break down actions I need to achieve into more manageable pieces:
- walking up to a crate with the shift key held will 'grab' the crate
- Sprite Animation would change to a holding animation
- Crate would lift 2-3 pixels off the ground.
- Crate would attach itself to the front of a side-profile / jumpnrun type player.
- Turning around would mirror the position of the crate
- Letting go of SHIFT while holding the crate would drop it in place.
Im clueless here... any help or advice on how to learn would be forever appreciated.
1 decade ago
by 80bit
I was looking through some past forum topics and found this:
4 months ago by geradr
AMAZING !
I'm not sure how you knew but it works now !
I'll pop the code here in case anyone needs it
update: function() {
var player = ig.game.getEntitiesByType( EntityPlayer )[0];
if( player ) {
this.pos.x = player.pos.x+2;
this.pos.y = player.pos.y+10;
}
this.parent();
}
Helpful, but i basically have my player connecting with the sprite when the key is held down and things go terribly awry. its almost like the collision of the sprite is causing it to overlap with the player and bounce them away from eachother etc. arg. I need to be able to interact with the crates as standard crates, so i can stand on them etc when the SHIFT key is not held. I realize im probably in over my head, but any help would be so awesome. :)
1 decade ago
by 80bit
OK, after some playing, I feel like I may be on the right track but im not sure if im doing it the correct way.... This is in my Crate.js entity:
check: function( other ) {
var player = ig.game.getEntitiesByType( EntityPlayer )[0];
//First check to see if we're holding down shift.
if( ig.input.state('grab') && this.touches( player ) ) {
if( ig.input.state('left') ) {
this.flip = true;
this.pos.x = player.pos.x-10;
this.pos.y = player.pos.y+0;
this.vel.y = 0;
this.vel.x = 0;
} else if( ig.input.state('right') ) {
this.flip = false;
this.pos.x = player.pos.x+10;
this.pos.y = player.pos.y+0;
this.vel.y = 0;
this.vel.x = 0;
} else {
this.pos.x = player.pos.x+10;
this.pos.y = player.pos.y+0;
}
}
},
Am i missing the mark? Everything is ok so far, but of course the 'moving' of the crate to be 'next to' the player means the player is no longer in contact with the crate. I am considering making the crate have PASSIVE collision so I can then drop it on top of the player and then switch it back to ACTIVE when i let go of SHIFT... but Im going to shut up and see if anyone can assist me with this because im worried im just fumbling through this and there's a simple straight forward solution..
i have an alternative idea to 'picking up' crates
once you collide with the crate, kill both entities (including the player). Then spawn the player holding the crate animation.
how it will roughly look like in code
// in crate.js
type: ig.Entity.TYPE.B
checkAgainst:function(other){
if(other == ig.game.player) ig.game.spawnEntity(EntityPlayerHoldingCrate,x,y);
}
1 decade ago
by 80bit
Ur a genius... that makes a lot of sense actually.. Then if the shift key is let go, respawn a crate and the original player in the same spot.. OK, im going to give this a go.... :) Thank you!!
Page 1 of 1
« first
« previous
next ›
last »