Hello, I've been trying to do a simple collision thing in my pokémon game, because I wanted to be able to walk "in front of trees" while touching them, and colliding with them only at a certain point, and not just colliding when the player is touching them. So I wrote a little code :
But the problem is, it only takes the variable from the first tree that was added into the world (as I added many), so it works perfectly for the first tree added, but not well for the other trees, as the treeX and treeY variable (just public int treeX and public int treeY) come from the same tree. I don't know how to make the actor get the variable from the specific tree he's touching. What can I do ?
if(isTouching(Tree.class))
{
treeY = ((Tree)getWorld().getObjects
(Tree.class).get(0)).getY();
treeX = ((Tree)getWorld().getObjects
(Tree.class).get(0)).getX();
if(getY() - treeY < 50)
{
setLocation(originalX, originalY);
}
if(getX() - treeX < 50)
{
if(treeX - getX() < 50)
{
setLocation(originalX, originalY);
}
}
}

