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

2019/5/27

Fixing if objects are intersecting

The_bazm The_bazm

2019/5/27

#
Hello, I have the problem that I don“t know how to teleport an object, if it intersects an other object, at the top of the object. I have a lot of objects and I want to ask if there is a way without knowing the height of the intersecting object.
Super_Hippo Super_Hippo

2019/5/27

#
You need half of the sum of the height of both actor's images. So basically:
setLocation(obj.getX(), obj.getY() - (getImage().getHeight() + obj.getImage().getHeight())/2);
with "obj" = the object which was intersected.
You need to login to post a reply.