alexsok90

Member
  • Content count

    5
  • Joined

  • Last visited

Community Reputation

127 Neutral

About alexsok90

  • Rank
    Newbie
  1. public float XVel = 1.0f; public void BallMove() { if (ball.X < 0 || ball.X > 420) XVel *= -1; ball.X += XVel; }   Something more readable.
  2. Turret rotation

    These values don't make any sense. Are you sure you are using Atan2 method? Also keep in mind that this code makes use of radian angles (not degrees). Or maybe your rotationSpeed value is too high. In my project it was like 0.02f (i was calling this method every update).   #EDIT You can also try replacing that "else if" with "if" only. Or swapping Atan2 arguments from "src - target" to "target - src".
  3. Turret rotation

    Ah, sorry - this topRotation should be currentRotation. I was renaming the variables and missed this one.
  4. Turret rotation

    Here is the code from tank game I developed. It rotates the turret clockwise or counter-clockwise (depeding on which path is shorter) with desired speed.   destinationRotation = Math.Atan2(turret.Y - target.Y, turret.X - target.X) + Math.PI; if (destinationRotation != currentRotation) { if (destinationRotation > currentRotation) { if (currentRotation < destinationRotation - Math.PI) currentRotation -= rotationSpeed; else currentRotation += rotationSpeed; } else if (destinationRotation < topRotation) { if (currentRotation > destinationRotation + Math.PI) currentRotation += rotationSpeed; else currentRotation -= rotationSpeed; } if (currentRotation > Math.PI * 2.0f) currentRotation = 0; if (currentRotation < 0) currentRotation = Math.PI * 2.0f; }