How to make linear moition? I make an Arcanoid and ball must move without gravitation. But how?
Linear motion, how?
FlashUse zero gravity, when creating the world.
I did it, but need that only for ball gravity = 0. And when gravity zero ball was stopping anyway, striking with other bodies.
You cannot disable gravity for just some objects. Instead, turn off gravity, an apply your own gravity (a force proportional to mass) to bodies you want it for.
You want restitution to be 1 for things to bounce off each other elastically.
You want restitution to be 1 for things to bounce off each other elastically.
Thanks, but ball still stoping, even if gravity set zero and restitution set 1.0.
I try to set resultant velosity vector is constant in each timeStep, except collision.
I try to set resultant velosity vector is constant in each timeStep, except collision.
It's not good, in that way ball moving with constant velosity, but direction still depend from gravitation.
honestly arkanoid is not the type of game you should use a physics engine for. just code it all and it will go much smoother.
I mean, I'm sure you could use box2d and put a new spin on it. but if its that classic feel you want then its a lot less work just to make it from scratch ironically
I mean, I'm sure you could use box2d and put a new spin on it. but if its that classic feel you want then its a lot less work just to make it from scratch ironically
I ran into this same problem in another project -- I was making a game prototype where objects had to travel as if they were Arkanoid-like balls, but everything else in the world still had to act like they were real physical objects.
Basically, what I did is something like this...
Now, I don't know if normalizing and setting the velocity every frame is all that efficient, but for the purposes of my prototype, it worked great. My ball would bounce off of things correctly, everything it hit would like they had been hit by a real moving object, and everything just kinda worked. Maybe try that for your Arkanoid-like game and see how it goes...
Basically, what I did is something like this...
Code:
function myUpdateFunctionCalledEveryFrame() {
var currentVel:b2Vec2 = _body.GetLinearVelocity();
currentVel.Normalize();
currentVel.Multiply(IDEAL_BALL_SPEED);
_body.SetLinearVelocity(currentVel);
}
var currentVel:b2Vec2 = _body.GetLinearVelocity();
currentVel.Normalize();
currentVel.Multiply(IDEAL_BALL_SPEED);
_body.SetLinearVelocity(currentVel);
}
Now, I don't know if normalizing and setting the velocity every frame is all that efficient, but for the purposes of my prototype, it worked great. My ball would bounce off of things correctly, everything it hit would like they had been hit by a real moving object, and everything just kinda worked. Maybe try that for your Arkanoid-like game and see how it goes...
I'm not sure.. but you can try to use prismatic joint! 😀
Original thread: https://box2d.org/forum/viewtopic.php?t=2126