Advertisement Jump to content
  • Advertisement

LazyDev

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About LazyDev

  • Rank
    Newbie

Personal Information

  • Role
    Game Designer
    Level Designer
    Programmer
  • Interests
    Design
    Programming
  1. Here is what I use to update the rotation. int jump = 10; float pos_rot = (360 + newRot - rot) % 360; float neg_rot = 180; if (pos_rot < neg_rot) { rot += jump; pos_rot = (360 + newRot - rot) % 360; neg_rot = 180; if (pos_rot > neg_rot) rot = newRot; } else { rot -= jump; pos_rot = (360 + newRot - rot) % 360; neg_rot = 180; if (pos_rot < neg_rot) rot = newRot; } this.rotation = new Quaternion().fromAngleAxis(rot*FastMath.DEG_TO_RAD, Vector3f.UNIT_Y); Here is how i get the "newRot" variable. Vector2f mp = inputManager.getCursorPosition(); double xDiff = (settings.getWidth() / 2) - mp.x; double yDiff = mp.y - (settings.getHeight() / 2); gl.player.newRot = (int) (Math.atan2(xDiff, yDiff) * FastMath.RAD_TO_DEG); I used System.out.println(gl.player.newRot < -360 || gl.player.newRot > 360); to debug it, and it never goes over 360 or under -360. So I don't think I'm inputting anything out of the designated range.
  2. After a while, the player can only turn left for some reason 🤔
  3. Thanks guys int jump = 5; int sub = rot - newRot; if ((sub < -180 && sub > -360) || (sub < 180 && sub > 0)) rot -= jump; else rot += jump; It works now.
  4. I have a player who's rotation is y-axis only and controled by a function which sets a new rotation variable to the new value. What I need to figure out is which direction to turn, so the player has to move the least. What messes me up is the fact that degrees are 0-360. Anything that dosen't have to go past the 0/360 point works fine. My variables are the current rotation, and the wanted rotation. Any ideas? Thanks
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!