Pau Posted July 25, 2018 Share Posted July 25, 2018 I am making a car racing game. When i rotate the car, it doesen't rotate well. It is rotating in a weird way. I did set the origin to the 0,0 with following code in order to make it match with the tiled editor origin. But, after that, the rotation is wrong. player1 = this.physics.add.sprite(500, 500, 'car1').setOrigin(0 , 0) Before start rotating: After be rotating for a while: I put the game code in the attachment. Thank you in advance. cars.zip Link to comment Share on other sites More sharing options...
rich Posted July 25, 2018 Share Posted July 25, 2018 Origin(0,0) is the top-left, so the rotation looks right to me. You surely want 0.5, 0.5 so it rotates from the center? NoxBrutalis 1 Link to comment Share on other sites More sharing options...
Pau Posted July 26, 2018 Author Share Posted July 26, 2018 Sorry, i believe that the explanation of my problem wasn't clear. I think that if the car rotates from its top-left corner it will be a wrong behaviour when you are playing. So i want it to rotate from its 0.5,0.5 position. The problem is when i import the position of the elements from tiled editor. I have prepared this example: https://pablomonteserin.com/apuntes/web/js/canvas/phaser/ex/coches/cars-foro-phaser/ In the example i have two cars. Both are right positioned in the tiled editor. In the tiled editor, both are just after the whilte line, in its center. But when i import the json generated with tiled to phaser, i must use setOrigin(0,0) to maintain the right location. In my online example, i didn't use setOrigin(0,0) for the second car, so it is wrong positioned: But if i change the origin to the 0,0 point, the rotation is not working fine. It is not rotating from its center and i believe it is a wrong behaviour when you are playing. I did put the game with the tiled editor map in the attachments. Thank you in advance. cars-foro-phaser.zip Link to comment Share on other sites More sharing options...
NoxBrutalis Posted July 26, 2018 Share Posted July 26, 2018 yeah, rotating things in tiled is a bad idea normally. As it doesn't translate very well. I had the same problem with walls in my map. I had thought i could could copy sections of my map in tiled, and rotate them for faster map making, but in phaser they came out all wrong. Instead of changing your cars origin to 0,0 to get it where you want, you should figure out the offset from it's intended position. so for example in your picture above where you didnt change the origin to 0,0 and it's in the wrong place, add half the width and half the height to the x and y positions and it should be where you want it to be. Link to comment Share on other sites More sharing options...
Recommended Posts