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

2016/8/27

Change anchor point of Actor

Genora51 Genora51

2016/8/27

#
Hi. I am making a test program regarding raycasting/basic 3d etc. I have a class which gets detected by my raycasting object, which moves around my world to detect walls, enemies, and the like. When the raycaster touches the object, it needs to detect how far along the object it is, to work out which part of the object to render first. However, since the anchor point of an object is in the centre, I have no way of knowing whether I am more or less than halfway: Because the Actor rotates, I cannot simply do an x/y check to see which is the case, so it would be much easier to calculate distance to one corner of the object, i.e. shifting the anchor point to the corner. I also am unable to just enlarge the image, since it is already invisible and so my intersection test would pick up parts beyond the enlargement. Is there any way to change the anchor/pivot point of my class, or is there another workaround, to find distance to the corner or otherwise?
NAMYA0303 NAMYA0303

2016/8/28

#
can u explain it in a simple way Genora
Genora51 Genora51

2016/8/28

#
When my main class touches a line I need to work out how far from the end of the line I am.
Genora51 Genora51

2016/8/28

#
But I can't change the size of the line's image.
danpost danpost

2016/8/29

#
Genora51 wrote...
When my main class touches a line I need to work out how far from the end of the line I am.
Which end of the line? If the rotation of the line was zero, would you then want the distance from the left end of the line??
Is there any way to change the anchor/pivot point of my class
There is no way to change the pivot point that the Actor holds (those returned by 'getX' and 'getY'). However, you could artificially construct a pivot point more to your liking by adding a set of coordinate values that represent the end of a ray. When changing the position of the ray, reset the location back to the pivot point, change the angle/size of the ray and 'move' half its length in the new direction. By having the point retained by the ray, the issue of finding the distance of the objects from the end of the line should be resolved.
Genora51 Genora51

2016/8/29

#
I worked out a solution based on the dimensions of my class. I created a pointer class which sets location to the main one then moves to the end. I can then keep track of the distance from the end.
Genora51 Genora51

2016/8/29

#
Ps : to Danpost - I don't think I have seen a single forum post that you haven't replied to. Thank you so much for the help you have given on so many occasions to just about everyone. (Are you one of the developers of greenfoot?)
danpost danpost

2016/8/29

#
Genora51 wrote...
Ps : to Danpost - I don't think I have seen a single forum post that you haven't replied to. Thank you so much for the help you have given on so many occasions to just about everyone. (Are you one of the developers of greenfoot?)
You might want to see this discussion.
You need to login to post a reply.