Gamerazor Posted April 6, 2015 Share Posted April 6, 2015 Hello Im doing the game like arkanoid. The problem is when I try to move the bar with physics. When the bar has collided with the wall it lose the path and don't move straight to left to right. When I also try with moveWithCollisions() it works bad when the bar collide with the ball. How can I resolve this? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 6, 2015 Share Posted April 6, 2015 you can simply add an invisible wall behind the bar to keep it in line Quote Link to comment Share on other sites More sharing options...
Gamerazor Posted April 7, 2015 Author Share Posted April 7, 2015 but, won't the bar bounce forward? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 7, 2015 Share Posted April 7, 2015 crap! that's right The problem is that this is a physics engine and is goal is to simulate physics Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Gamerazor Posted April 9, 2015 Author Share Posted April 9, 2015 then how can i resolve this problem?because the ball needs the physics engine and the bar needs collide with the ball. Quote Link to comment Share on other sites More sharing options...
Gamerazor Posted April 9, 2015 Author Share Posted April 9, 2015 ok the problem is resolved with: barra = Balltingo.getMeshByID("Bar")body = barra.setPhysicsState(BABYLON.PhysicsEngine.BoxImpostor,{mass: 1000, friction: 0.00001, restitution:0.00001}) move = (body,barra) -> s= 2 if body.moveLeft barra.applyImpulse(new BABYLON.Vector3(0,0,-s),barra.position) else if body.moveRight barra.applyImpulse(new BABYLON.Vector3(0,0,s),barra.position) body.body.linearVelocity.scaleEqual(0.92) body.body.angularVelocity.scaleEqual(0) return #this is coffescript Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 9, 2015 Share Posted April 9, 2015 Hi Ahh, you made the bar very heavy... good idea! You may still see the bar move a small amount every time the ball hits it. Do you know that physics engines sometimes zero-out rotations on a mesh... when you do mesh.setPhysicsState? (It is because they switch to quaternion-based rotation, I believe). Now, think about doing this (pseudo code) inside a render loop/animation loop: bar.clearPhysicsState()bar.fixMyBarZpos() // reset bar z-position in case the ball has been "pounding it downward"bar.setPhysicsState(just like initially) You probably won't need a .fixMyBarRotation() because... as stated earlier... sometimes .setPhysicsState resets the rotation automatically. Essentially, once per frame, you shut off physics for the bar, fix any positional problems with the bar, and then setPhysicsState on the bar again.... which should null-out any ball-caused rotation. And maybe... IF you DO this... and then lower the mass on the bar again, MAYBE you will see the ball actually "shoot" away from a bar. This happens because you are moving the bar forward just after a ball has hit the bar backwards a small amount. When you move the bar forward (to normal placement), and re-set its physics state... the ball may still be touching the physics imposter for the bar. So, the ball might "spring" off the bar with more restitution than you planned-for. But it's all fun. Possibly, the lower the mass for bar, the more ball spring. But you also have restitution settings on ball and bar... to adjust everything as you wish. You might also try this same sneaky method for moving your bar left and right. Instead of using applyImpulse to move the bar, use the animation loop: bar.clearPhysicsState()bar.adjustPos() // reset bar z-position and check for +/-X movement needed (player input). If needed, do it.bar.setPhysicsState(just like initially) // re-apply the physics state after the position adjustments. Wow, huh? Just a thought. I don't know if this idea will help you, but maybe. I HAVE used this method to position objects that were physics-active (most of the time). Quote Link to comment Share on other sites More sharing options...
Gamerazor Posted April 11, 2015 Author Share Posted April 11, 2015 thank you wingnut but i only had problem when the bar collided with the left wall but I have resolved this problem with this way:move = (body,barra) -> s= 2.5 if body.moveLeft && barra.position.z > -5 barra.applyImpulse(new BABYLON.Vector3(0,0,-s),barra.position) else if body.moveRight barra.applyImpulse(new BABYLON.Vector3(0,0,s),barra.position) body.body.linearVelocity.scaleEqual(0.92) body.body.angularVelocity.scaleEqual(0) return Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.