Alastair Posted September 16, 2014 Share Posted September 16, 2014 Hello everyone! I'm new to Phaser, so please bear with me if I have missed anything obvious. I am currently creating a pinball game, using the P2 physics option, and have managed to setup the level (static object) and ball (standard circle object) easily enough. I have setup gravity etc. But I am having a lot of problems with the flipper/paddles... - The problem I have is I want to set the flipper to static, but still be able to rotate it using the rotate methods. It doesn't seem like you can do this. Various angle/rotation variables are exposed on the game objects and their bodys, but assigning to these manually has inconsistent effects. So, I then tried setting the mass to 9999 and gravity to 0 so I can apply nice rotation methods... but I still find it slowly moves off its original position as I apply rotateLeft/Right to it. I could just force it back to its original x/y but that seems a bit poo. I'd really love to be able to set it to static, and have a nice rotation 'flick' function. - I have found this guy who made a pinball game, and he is using something called "revolutes". I tried copying his code and adjusting just as much as is necessary so it runs on the latest version of phaser (such as updating his math functions), but this always sets my paddle in a negative x,y position. http://georgiee.github.io/phaserpinball/https://github.com/georgiee/phaserpinball/tree/master/source/javascripts What really annoys me about his project is that he doesn't seem to be telling the paddles to stay in place (through static or gravity modifiers or any other means that I can spot), they "just do". Does setting up a revolute fix an object into one place? Hopefully someone can follow along and help. Thank you very much in advance. Link to comment Share on other sites More sharing options...
valueerror Posted September 16, 2014 Share Posted September 16, 2014 creating a revolute constraint is a very good way to do this.. this is one of many constraints phaser can do but for your purpose i guess its the best choice.. http://docs.phaser.io/Phaser.Physics.P2.RevoluteConstraint.html Link to comment Share on other sites More sharing options...
wayfinder Posted September 16, 2014 Share Posted September 16, 2014 Take a look at the "kinetic" motionState as well! Link to comment Share on other sites More sharing options...
valueerror Posted September 16, 2014 Share Posted September 16, 2014 this is how you would create such a constraintconstraint1=game.physics.p2.createRevoluteConstraint(rectangle1, [0,-40], rectangle2, [-20,20], 10000);the numbers in the brackets are the X and Y offsets of the constraint to the centers of the bodies Link to comment Share on other sites More sharing options...
Alastair Posted September 16, 2014 Author Share Posted September 16, 2014 Thank you very much for your help the both of you, I will take a look at both of these to see if it helps Link to comment Share on other sites More sharing options...
Alastair Posted September 16, 2014 Author Share Posted September 16, 2014 Kinetic motionState was exactly what I was after <3 Will look further into revolute constraints to see how it can improve my rotation 'animation'. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts