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

2012/6/28

Rotation and getOneIntersectingObject

limefortheworld limefortheworld

2012/6/28

#
This is an interesting observation: I presumed that the getOneIntersectingObject works with collision boxes the size of the image itself, which would have meant that slanted things would still "hit" something that checks collision off the getOneIntersectingObject method should say it collides if a diagonal image collides with another thing at the would-be rectangle defined by the width and height of the new diagonal image.
GreenfootImage baseimage = new GreenfootImage(right[0]);
baseimage.scale((int)(Math.sqrt(Math.pow(ix-target.getX(),2) + Math.pow(iy-target.getY(),2))), left[0].getHeight());
setRotation((int)Math.toDegrees(Math.atan2((target.getY()-getY()),(target.getX()-getX()))));
setLocation((ix+target.getX())/2, (iy+target.getY())/2);
setImage(baseimage);
But surprisingly enough, with the rotated object, it seems like the hitbox is altered so that it only counts the rotated/stretched boundaries of the original image, not defining the hitbox as a new rectangle that encompasses the new image. Hence putting something at say the other corner of the would-be rectangle does not score an hit. How is it so? If requested, I may upload the scenario as a reference.
danpost danpost

2012/6/28

#
limefortheworld wrote...
I presumed that the getOneIntersectingObject works with collision boxes the size of the image itself
You presumed correctly. The image is still the same size after rotating.
limefortheworld wrote...
which would have meant that slanted things would still "hit" something that checks collision off the getOneIntersectingObject method should say it collides if a diagonal image collides with another thing at the would-be rectangle defined by the width and height of the new diagonal image.
Here is where you went amiss. The 'hit' rectangle is rotated with the image. There is no re-defining of the size of the image to make your 'would-be' rectangle.
limefortheworld limefortheworld

2012/6/28

#
I was thinking that was the potential answer. I guess then it is how it goes.
You need to login to post a reply.