This site requires JavaScript, please enable it in your browser!
Greenfoot back
YuEmAydin
YuEmAydin wrote ...

2018/11/20

Gravitation-Simulator

YuEmAydin YuEmAydin

2018/11/20

#
Hello guys, I have problems with this Code. The Problem is that the Ball wont stop moving:
import greenfoot.*;

import java.util.List;
import java.util.ArrayList;


public class Ball1 extends Actor
{
    private double ho=0, vo=0, g=10, dt=0.25;
    
   
    public void addedToWorld(World Latar)
    {
        ho=getY();
   
    
    }
   
   
    public void act()
    {   
        if(getY()<(getWorld().getHeight())){
        double ht=ho+vo*dt+0.5*g*dt*dt;
        vo+=g*dt;
            if(ht>(getWorld().getHeight())){
                ht=(getWorld().getHeight());
                vo*=-0.835; //Federung
            }
            
        setLocation(getX(),(int)ht);
        ho=ht;
    }
  
     
}
    
}
danpost danpost

2018/11/20

#
YuEmAydin wrote...
I have problems with this Code. The Problem is that the Ball wont stop moving: << Code Omitted >>
In a bounded world, the y-coordinate value will never be equal to or greater than the height of the world. That being said, the condition in the first line in your act method will ALWAYS be true.
YuEmAydin YuEmAydin

2018/11/25

#
God damn... Thanks for the answer it was very helpful.
You need to login to post a reply.