but something strange happens. It will rotate just fine at certain angles for example if the mob is coming from the left, but if it is coming from the top or right, the tower wont stay on target and will just slightly go up and then down and so on. Can anyone see any faults in this code?Thanks, cMp

but something strange happens. It will rotate just fine at certain angles for example if the mob is coming from the left, but if it is coming from the top or right, the tower wont stay on target and will just slightly go up and then down and so on. Can anyone see any faults in this code?Thanks, cMp

Cast to radians to degrees and then degrees to radians?Does not seem an good implementation.

The rotation.x is the number of degrees you want to rotate by. Then the other two or the center coordinates of the sprite you are rotating. Once you find your angle in degrees just plug it into that method with your sprites location and bam. It does the translations I believe itself.

The location on the screen. So if you have an image at (200,200) you would use that.

AphineTransform just means that you are doing the rotation around that object as if the point you are giving it is the origin. What you are doing with the translate is basically an AphineTranform as you want the image to rotate around a different origin then the screen.

This is funny, that code does the exact same thing as the old code did, rotates it fine from bottom and left, but when the mob comes from the top or right it just goes back and forth for about 45 degrees. Any ideas?

Try this. FastMath is just a class for faster trig calls. You may need to change how much you add after the rotation. I do 180 as I want the particles to point from the left of the image. So if you have an image like this

[-----][-<--][-----]

it would keep the arrow pointing in the direction the image is going. If you have an image that is not pointing either left, right, up, or down then you will not get exact results as the source image is off. This is why if you look at most AAA games 2D textures they point in one direction not to an angle.

why are you using float when affinetransform uses doubles? I thought it was a mistake in your first post, but now I guess its for a reason

EDIT: I am the most stupid person on this earth. I was putting angle as a double data type. Good lord. Thank you very much for your help you have solved a problem I have been trying to fix for a VERY long time

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org