java - LibGDX Angle/Rotation Issue -
i'm using tiled map editor create simple tiled map. within map have several rectangles, if create rectangle width of 50 , height of 10 , rotate 90°, save map , load in libgdx project, shape rendered correctly - if use random angle, let's 26° example , render map again, not desired result, in fact exact opposite desired angle.
i'm reading tiled map float directly map using:
map map = new tmxmaploader().load(maplocation + mapname + mapextension); (maplayer maplayer : map.getlayers()) { (mapobject mapobject : maplayer.getobjects() { mapproperties objectproperties = mapobject.getproperties(); float objectrotation = objectproperties.get("rotation") != null ? float.parsefloat(objectproperties.get("rotation").tostring)) : 0.0f; objectrotation = mathutils.degrad * objectrotation; } }
the mathutils.degrad
converts degrees read directly map properties radians, somewhere along line there's misread happening or i've missed something.
later, create bodydef , set angle above mentioned objectrotation
using bodydef.angle = objectrotation
followed creating body default values.
you're missing bit of math.
mathutils.cosdeg( angleindegrees ) mathutils.sindeg ( angleindegrees )
Comments
Post a Comment