so i’m trying to create a proper ‘freeze in mid-air’ then do a ‘bouncing fall’ off the screen like in sonic the hedgehog HERE :
instead of using “sprite.setY ( )” for creating a “get hit by spike” effect, how can I create a ‘bouncing’ effect based on arcade physics? i need control of how high or low the player goes flying & WHICH direction the player goes flying. i tried setVelocity , that didn’t work.
@samme : Why is it when I’m holding down a movement key or jumping key, switch tabs then go back, OR I disable key input completely, is my character still moving / jumping automatically even though they should not be able to move at all? How do I fix this?
This is my 'playerHit ( )' function :
/**
* playerHit resets the player's state when it dies from colliding with a spike
* @param {*} objData - any Data we may need
*/
playerHit : function ( __objData ) {
this.__objData = __objData;
this.__input = this.__objData.input;
this.__map = this.__objData.map;
this.__layerName = this.__objData.layerName;
this.__player = this.__objData.player;
this.__hitObject = this.__objData.collidedWithObject;
this.__set_x = this.__objData.setx;
this.__set_y = this.__objData.sety;
this.__xvel = this.__objData.xvel;
this.__yvel = this.__objData.yvel;
this.__tweens = this.__objData.tweens;
if ( typeof ( this.__objData ) !== 'object' ) { return console.error ( 'ERROR :: { Please ensure you are using an `object` for `objectData` & try again } !' ); }
// Set velocity back to 0
this.__player.setVelocity ( 0, 0 );
// Disable input & Collision
this.__input.keyboard.enabled = false;
this.__player.body.checkCollision.none = true;
// Stop Player Animation{s}
StopAnimation ( this.__player );
// Set `Player` Animation to `idle`
PlayAnimation ({
sprite : this.__player,
animName : 'idle',
loopAnim : true,
});
// Set Velocity
if ( this.__set_x === true ) { this.__player.setVelocity ( this.__xvel, 0.0 ); }
if ( this.__set_y === true ) { this.__player.setVelocity ( 0.0, this.__yvel ); }
// OR set BOTH Velocities
if ( this.__set_x === true && this.__set_y === true )
{
this.__player.setVelocity ( this.__xvel, this.__yvel );
}
// Set the visibility to 0 i.e. hide the player
this.__player.setAlpha ( 0 );
// Add a tween that 'blinks' until the player
// is gradually visible
let tw = this.__tweens.add ( {
targets : this.__player, alpha : 1, duration : 100,
ease : 'Linear', repeat : 3,
} );
},
@samme : just did this & it’s still not stopping the x-velocity from firing. i need it to stop the character in mid air, activate the bounce effect ( y-velocity ), then fall down through the level.
@samme : setting a gameOver variable works WONDERS. But I have a small issue. For some reason even though I do :
// Set `velocity` back to `0`
this.__player.setVelocity ( 0, 0 );
this.__player.setVelocityY ( -600 );
inside the loop ( which is where the 'this.__player.setVelocity ( 0, 0 );' needs to be ), I get the player doing the fall correctly, but the y-velocity keeps on getting faster & faster. The problem is, I NEED the velocity set to 0 in order to keep the player from not moving to the sides AND in the air when running into a spike.
Any help is as usual, GREATLY appreciated!!! Thanks so much!
I guess I don’t understand the problem you’re describing. Visually, what happens now when your player hits a spike and what do you want to happen instead?