Domenik.B Domenik.B - 1 year ago 206
Java Question

Libgdx: transform vector2 around z-axis

I´m trying to port a tower defence game from xna (c#) to libgdx (java).

But now I have a problem, there is a function which rotates the bullets from the towers around the z-axis in direction to the enemies.

public void SetRotation(float value){
rotation = value;
velocity = Vector2.Transform(new Vector2(0, -speed), Matrix.CreateRotationZ(rotation));

This is the code in c# using xna. Does anybody know how to do this in libgdx?

Here ist the link form the tutorial side from the tutorial:

I hope there is someone who can help me..

Answer Source

Vector2#rotate rotate the vector around the Z axis. Note that it needs the angle in degrees. If the angle you have is in radians then use the rotateRad method.

velocity.set(0, -speed).rotate(value);
velocity.set(0, -speed).rotateRad(value);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download