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

2019/5/30

Fixing if objects are intersecting

The_bazm The_bazm

2019/5/30

#
What can I do if I don`t want the object to get stuck and not to teleport up:
1
2
3
4
5
6
7
8
9
public void fix () {
        try{
            Actor a = getOneIntersectingObject(null);
            setLocation(getX(), a.getY() - (a.getImage().getHeight() + getImage().getHeight())/2);
        }
        catch (Exception e) {
 
        }
    }
here my current code
danpost danpost

2019/5/30

#
The_bazm wrote...
What can I do if I don`t want the object to get stuck and not to teleport up: << Code Omitted >>
Better would be:
1
2
3
4
5
6
public void fix()
{
    Actor a = getOneIntersectingObject(null);
    if (a == null) return;
    setLocation(getX(), a.getY()-(a.getImage().getHeight()+getImage().getHeight())/2);
}
This will not actually change what your cod does; but avoids the try-catch structuring. As far as what you do not want, maybe you should explain what you do want. A detailed explanation is best.
The_bazm The_bazm

2019/5/30

#
ok. my current situation is that if the player is for example IN a block he should get teleported on the block. This is fine and also works. But my problem is that when the player even touches something he gets teleported up, too. For example if there is a jump and you would touch the wall or an element at the bottom normally the player just should continue falling. But now he teleports because of this method up and you can skip the whole level.
danpost danpost

2019/5/30

#
The_bazm wrote...
ok. my current situation is that if the player is for example IN a block he should get teleported on the block. This is fine and also works. But my problem is that when the player even touches something he gets teleported up, too. For example if there is a jump and you would touch the wall or an element at the bottom normally the player just should continue falling. But now he teleports because of this method up and you can skip the whole level.
Sounds like a jump-and-run type scenario. You will probably have to deal with horizontal and vertical movements separately and, in each, make use of the actual direction moved (right/left and up/down) to determine where to position the actor when an obstacle is encountered. Maybe taking a look a my Jump and Run Demo w/Moving Platform might help.
You need to login to post a reply.