So what I want, is that the licghtcone would point always to a mouse pointer. I read that, when attaching light to a body, it will automatically rotate to bodys direction. I have tried like changig the light direction and so, but it always seems to rotate just 180 and to an opposite direction. If u have any ideas, I would be glad .

Have you tried just putting the body to the opposite point? Like at width - X and height - y? Seems that would be a way of butchering things into what you want?

(Sorry, I don't have a lot of experience with box2d, it didn't produce an effect I had found desirable and ripped it out, just that's something I would try)

Hey, and thanks for your input.

Sorry, really didn't understand what u mean. Do u mean the light at the opposite point? My char is built up from 4 bodies (body, head, weapon & arm). Or do u mean the arm should be attached like the way u discribed? Sorry I'm little confused . Wierd thing thou, the arm is working nicely and rotating all the 360 degrees. Can't just understand why the light won't behave the same way.

My hypothesis of the issue, you're doing arm.setTransform(new Vector2(arm.getPosition().x, arm.getPosition().y), newAngle);and you're ALSO doinglight.setDirection(newAngle);My interpretation of Orange451's suggestion, and assumptions of the box2d api, would suggest you shouldn't be flipping (adding PI) to both the arm and the light, as that would just put the light back where it started. Try flipping only the light, not the arm. That is, revert line 9 to use anglearm.setTransform(new Vector2(arm.getPosition().x, arm.getPosition().y), newAngle);

Other notes,

does vec2.set(vec2.x, vec2.y); do anything? I'm not familiar with box2d, but assuming I understand correctly, that code seems redundant.

float angle = (float) Math.atan2(arm.getWorldCenter().y - worldCoords.y, arm.getWorldCenter().x - worldCoords.x);can be replaced by float angle = (float) Math.atan2(vec2.y, vec2.x);in order to make it both more efficient, and more importantly, easier to read.

You have some formatting issues. It's a good idea to format your spacing and such before posting online. After all, you're asking other people to offer their time and experience, the least you could do is make it easier for them to understand your problem. Most IDE's have a keyboard shortcut to auto-format.

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