I'm trying to develop a physics simulation for educational purposes, the game consist in a energy conservation demostration (spring, platform, ball) , the problem is when i have friction=0 ,it suposes that the ball will oscillate forever but at some time it stops, somebody knows how to fix it?,maybe is a physics problem between me and game platform but i was trying a lot of options and i'm not so experienced guy with C2.

Physics engines usually do no conserve energy, there is loss over time. The reason is everything is an approximation. You can however keep the energy close to being constant by correcting the velocity.

So the equation is this:

E=KE+PE

E=0.5*m*v^2 + m*g*h

solved for v

v = sqrt((E-mgh)*2/m)

So the events to correct the velocity so energy is conserved would be:

global number total_energy=0

global number initial_y=0

global number speed=0

global number angleOfMotion=0

Start of layout

--- set initial_y to ball.y

--- set total_energy to ball.physics.mass*10*(480-ball.y)

ball: y<initial_y

--- ball: set y to initial_y

every tick

--- set speed to sqrt((total_energy-ball.physics.mass*10*(480-ball.y))*2/ball.physics.mass)

--- set angleOfMotion to angle(0,0,ball.physics.velocityX,ball.physics.velocityY)

--- ball: physics: set velocity to ( speed*cos(angleOfMotion), speed*sin(angleOfMotion) )

The idea there is we need to keep the object's y position below the starting y. If the object goes above the sqrt in the equation will make the speed NaN because you can't get the square root of a negative number.

You mean in an exact way? The normal physics behavior should be a good approximation. You can turn up the iterations to make things more accurate with the "set stepping iterations" action of the physics behavior.

If you want an even more precise simulation, you'll basically need to make your own, but that would take lots of research and time.