Fixed angle (45, 135, 225, 315) in physics ball game

Hi, I’m developing a game in which i have a ball that moves and bounces across the screen. The player can change the vertical angle; if the movement angle is 45 degrees and I press a key, the angle and movement change to -45 degrees, and if it’s 135 degrees, they change to -135 degrees. I’m using the physics engine.

Everything works fine, but I need the angles to be fixed in only four directions (45, 135, 225, and 315 degrees). The problem arises when the ball hits an obstacle: it changes to other angles, but I need the only movement angles to be 45, 135, 225, and 315 degrees.

Is it possible to have fixed angles for movement in the physics engine?

Thanks

Not really… this wouldn’t make much sense for a physics simulation in general. However you could try to force it by using the Linear Velocity toward Angle action, with the velocity from Object.Physics2::LinearVelocity() and then the new angle, to preserve the speed of the object.

Are there other reasons why you are using Physics2 for this? Forcing non-physical behavior can get weird. Like in this case, the object is going to bounce off things which will of course change the angle and speed of it, and then you’re going to be trying to “override” that by forcing it into a specific angle, but then how do you know which angle to use? And if you’re calculating a new angle anyway, perhaps it is redundant or unnecessary to use Physics2 at all?

I see. I was interested in the circular collision mask that the physics has. Whe i tried to use poligonal shapes, but sometimes the bounce had errors.