Jump to content

Reflect body p2


instantia
 Share

Recommended Posts

But if it still doesn't work, I think you could reset each of its X coordinates.

// Considering its anchor is [0.5,0.5]for(var i=0; i<this.body.shapes[0].vertices.length;i++){    this.body.shapes[0].vertices[i][0] = -this.body.shapes[0].vertices[i][0];}

If it doesn't not work (it probably wouldn't since you would be changing the geometry of an existing shape), you could create your own "vertices" tab like so:

var myVertices = [];for(var i=0; i<this.body.shapes[0].vertices.length;i++){    myVertices.push([-this.body.shapes[0].vertices[i][0], this.body.shapes[0].vertices[i][1]]);}// Now I have a vertices array, with coordinates (which looks like [[-200,200],[-150,100],[50, 150],...])// I erase the current bodythis.clearShapes();// I set the new body with my new coordinatesthis.loadPolygon(myVertices);
Link to comment
Share on other sites

{

"salmon_right": [

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 29, 84 , 28, 69 , 73, 65 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 190, 95 , 122, 111 , 91, 104 , 101, 32 , 115, 23 , 155, 26 , 196, 53 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 73, 65 , 101, 32 , 91, 104 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 233, 52 , 237, 65 , 212, 91 , 190, 95 , 196, 53 ]

}

],

"salmon_left": [

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 29, 84 , 28, 69 , 73, 65 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 190, 95 , 122, 111 , 91, 104 , 101, 32 , 115, 23 , 155, 26 , 196, 53 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 73, 65 , 101, 32 , 91, 104 , 74, 90 ]

} ,

{

"density": 2, "friction": 0, "bounce": 0,

"filter": { "categoryBits": 1, "maskBits": 65535 },

"shape": [ 233, 52 , 237, 65 , 212, 91 , 190, 95 , 196, 53 ]

}

]

}

Link to comment
Share on other sites

The interesting thing is that if you put the shift on the same "right", everything works fine.
 

if (this.obj.angle !== this.angleOld) {			if (Math.abs(this.obj.angle) > 90) {					this.obj.scale.setTo(this.scale, -this.scale);				this.dir = 'left';			}			else if (Math.abs(this.obj.angle) <= 90) {					this.obj.scale.setTo(this.scale, this.scale);				this.dir = 'right';			}			if (this.dir !== this.dirOld) {					/*console.log(this.obj.height);*/				this.obj.body.clearShapes();				this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);			}			this.dirOld = this.dir;		}

- not working.


 

if (this.obj.angle !== this.angleOld) {			if (Math.abs(this.obj.angle) > 90) {					this.obj.scale.setTo(this.scale, -this.scale);				this.dir = 'right';			}			else if (Math.abs(this.obj.angle) <= 90) {					this.obj.scale.setTo(this.scale, this.scale);				this.dir = 'right';			}			if (this.dir !== this.dirOld) {					/*console.log(this.obj.height);*/				this.obj.body.clearShapes();				this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);			}			this.dirOld = this.dir;		}

- working.


How so? left = right.

Link to comment
Share on other sites

solved the problem so:

 

if (Math.abs(this.obj.angle) > 90) this.dir = 'left';else if (Math.abs(this.obj.angle) <= 90) this.dir = 'right';if (this.dir !== this.dirOld) {		this.obj.scale.setTo(this.scale, this.scale);	this.obj.body.clearShapes();	this.obj.body.loadPolygon('physics', this.name+'_'+this.dir);}if (Math.abs(this.obj.angle) > 90) this.obj.scale.setTo(this.scale, -this.scale);else if (Math.abs(this.obj.angle) <= 90) this.obj.scale.setTo(this.scale, this.scale);this.dirOld = this.dir;

a bit expensive(

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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