Move items all time with Physics

I have circle into Physics world.
How i can move the circle into the worlds always and keep it move when circle hit the borders. (break the angle)
like in snake game

image

I think these types of games are not made with physics... perhaps if you need things bouncing off the sides of the "wall" then maybe you could Rectangle objects with addPhysics(false) for static objects. Hitting the outside wall, would be a conditional if () statement or possibly a contact() method in Physics.

If you are talking about a moving physics object leaving a trail of physics walls... that would be kind of cool to see - again, you could dynamically make static physics objects at the location of the ball as it bounces around.

Not sure exactly what you are looking for.

i want the ball move into the walls all time

What do you mean into the walls? And what do you mean move? Do you mean keep the ball within the walls? Or put the balls on the walls and move along the walls? How is the ball moving? Mouse or forces?

I want the ball always move
like that:

Ah... good question. Not in physics, that is pretty easy to do. Classic pong. ZONG - we should make a simple version of it. We have a multiplayer version and this double paddle version... not sure if we have just a simple version around somewhere (maybe I will make one this afternoon). So you could do it outside of physics and then constantly set the x and y property of the physics object body to the calculated location. We are not supposed to do that "act of god" but you have done that before.

Another way would be to set a force() in a Ticker.add() and have that pointing in a direction then when it contacts a wall, calculate the rebound angle and start setting the force to that angle. But then when it hits something else, it should calculate the new angle to apply the force... not sure... each contact, stop the force at first contact and calculate a new vector after .1 seconds or something and then start applying the force again based on that vector. I would have to test... will try soon.

Thanks!
I want it becuse i want save the power of the move and use the physics for my game (if it possible)

Just give the ball a continuous force in a ticker. object.force(x,y) You will just need to calculate the angle after the wall collision.

let circle = ...
circle.forces = {x:1,y:1};
circle.contact(function (wall) {
    //circle.forces = calculate new forces;
});
Ticker.add(()=>{
    circle.force(circle.forces.x,circle.forces.y);
});
1 Like

We did it! Used setLinearVelocity() as well to avoid acceleration - try it without and see what we mean...

1 Like

You can add some randomness to the change so it feels a lot more natural. Unless we're working with a perfect circle.

1 Like