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

2013/6/12

How to make gravity

carhad carhad

2013/6/12

#
I need grav. in my game so I want to know how. I have one characters class and I will have 4 Object classes. (As in ground stuff.)
carhad carhad

2013/6/12

#
Oh I forgot I need to detect collisions on all 4 sides too! I looked at the Greenfoot API but couldn't make sense of it.
carhad carhad

2013/6/12

#
Help?
Zamoht Zamoht

2013/6/12

#
Okay I don't know how much you need but here is one way to work around the problem. First of all put a fall method in your act()
public void act()
{
     if (notOnGround())
    {
         fall();
    }
}
The notOnGround() would have to detect wether the hero/player what ever is on the ground (please tell me if you need help with that too). The fall code could be very simple and look like this:
public void fall()
{
     setLocation(getX(), getY() + 1);
}
Though I have seen some people on this site using acceleration and stuff to make the fall look more realistic. For the collision part I would like to know what you mean exactly. Is it platforms, the world edges or something else you want to check collision with?
carhad carhad

2013/6/12

#
There are platforms plus bricks in the middle of the world to jump on and stuff.
Gevater_Tod4711 Gevater_Tod4711

2013/6/12

#
Maybe this engine can help you: Grafity Engine
You need to login to post a reply.