Jump to content

arcade.overlap on a rotating sprite not working ?


csimpson.web
 Share

Recommended Posts

Hi ..

 

Seem to have run into an issue when trying to get a rotating spite to overlap another sprite... it just doesnt recognise it as it rotates.

 

Is it even possible to do this?

 

think of a lighthouse beam and a rock . as the beam rotates and goes over the rock, it should catch and console.log , but it doesnt..

 

I've set the beam to static , moved the rock onto/and outside of, and it fires no problem..

 

If anyone knows why , please , put me out of my misery :huh::lol:

var playState = {	create: function() {	//Load the background image	this.background = game.add.sprite(0, 0, 'background');	this.background.anchor.x = 0;	this.background.anchor.y = 0;    //this.rock = game.add.sprite(120, 500, 'rock');    //this.rock.inputEnabled = true;	this.boat = game.add.group();    this.boat.enableBody = true;    this.boat = this.boat.create(24, 600, 'boat');    this.boat.inputEnabled = true;    //this.boat.body.drag = 800;    //Place the beams Last to set the Z accordingly    this.beam = game.add.sprite(257, 630, 'lightbeam');    this.beam.anchor.x = 0.1;    this.beam.anchor.y = 0.9;    this.beam.inputEnabled = true;    /*    this.beam2 = game.add.sprite(508, 370, 'lightbeam');    this.beam2.anchor.x = 0.1;    this.beam2.anchor.y = 0.9;    this.beam3 = game.add.sprite(683, 629, 'lightbeam');    this.beam3.anchor.x = 0.1;    this.beam3.anchor.y = 0.9;	*/	// higher Z Test Rock	this.rock = game.add.sprite(210, 500, 'rock');	this.rock.inputEnabled = true;	game.physics.arcade.enable(this.beam);    //game.physics.arcade.enable(this.boat);    game.physics.arcade.enable(this.rock);	},	rockBeam: function(rock,beam){		console.log('the beam is touching the rock!! hurrah !');	},	/*	// Working Overlay	rockBeam: function(boat,rock){		console.log('on/off');	},	*/	update: function() {		if (game.input.mousePointer.isDown)		{			//Give the boat some acceleration			//game.physics.arcade.velocityFromAngle(this.boat.angle, 100, this.boat.body.velocity);			//game.physics.arcade.accelerationFromRotation(this.boat.angle, 50, this.boat.body.acceleration);						if(this.boat.x < 200){				game.physics.arcade.accelerateToXY(this.boat, 200, 500, 80, 250, 50);			} else if(this.boat.x < 400){				game.physics.arcade.accelerateToXY(this.boat, 400, 500, 80, 150, 50);			} else if(this.boat.x < 600){				game.physics.arcade.accelerateToXY(this.boat, 600, 600, 80, 150, 50);			} else if(this.boat.x < 800){				game.physics.arcade.accelerateToXY(this.boat, 800, 500, 80, 150, 50);			} else if(this.boat.x < 1000){				game.physics.arcade.accelerateToXY(this.boat, 1000, 500, 80, 150, 50);			}			//  First is the callback			//  Second is the context in which the callback runs, in this case game.physics.arcade			//  Third is the parameter the callback expects - it is always sent the Group child as the first parameter						//this.boat.(game.physics.arcade.moveToPointer, game.physics.arcade, false, 200);						} else {				//game.physics.arcade.accelerationFromRotation(this.boat.angle, -10, this.boat.body.acceleration);				game.physics.arcade.velocityFromAngle(this.boat.angle, 0, this.boat.body.velocity);			}			if(this.boat.body.acceleration < 0){				this.boat.body.acceleration = 0;			}			// Rotation commented out as to highlight the overlay issue			//this.beam.rotation += 0.01;			//this.beam2.rotation -= 0.008;			//this.beam3.rotation += 0.01;			// working overlap			//game.physics.arcade.overlap(this.rock , this.boat , this.rockBeam, null, this);			// weird response			game.physics.arcade.overlap(this.rock , this.beam , this.rockBeam, null, this);						//TODO: remove : Making Sure they work			//console.log(this.boat);			//console.log(this.beam);			//console.log(this.rock);			//console.log(this.rockBeam);		},};
Link to comment
Share on other sites

Phaser's Arcade bodies do not rotate. The sprites do, but the underlying rectangular bodies do not - they are always rectangular and always aligned with the screen - this is called 'axis aligned bounding box' collision detection. If you do game.debug.body in the render function on your beams you'll see what's happening more clearly.

 

I realise this causes a lot of problems for your type of game, but there's no real way around this with Arcade physics. P2 has support for rotating polygon collision hulls, if you can make the change to that easily. Otherwise you may be looking at coding your own kind of raycast function a bit like the one here, and using that to detect the ships.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...